COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
pointer_string.cpp File Reference
#include <iostream>
#include <string>
Include dependency graph for pointer_string.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void )

Definition at line 6 of file pointer_string.cpp.

7{
8 // accessing member functions of a class
9 string s = "good day!";
10 string * sPtr = &s; // sPtr points to s
11
12 cout << "length of string: " << s.length() << endl;
13 cout << "1st word: " << (*sPtr).substr(0, 4) << endl;
14 cout << "2nd word: " << sPtr->substr(5, 3) << endl;
15
16 cout << "sixth letter: " << (*sPtr)[5] << endl;
17
18 return 0;
19}