COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
pointer_string.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3using namespace std;
4
5
6int main()
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}
int main()