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>
3
using namespace
std;
4
5
6
int
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
}
main
int main()
Definition
pointer_string.cpp:6
Module8
Sample Code
Pointers
pointer_string.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0