// Heading
#include <iostream>
#include <string>
using namespace std;
int main ( )
{
// Declaration
string s1;
string s2;
string s3;
string s4;
// Assignment
s1="How old
are you ?";
s2.assign(s1);
// or s2=s1;
s3="I'm fine.";
s4.assign(s1,8,14);
// Direct display
cout <<
"s1= " << s1 << endl;
// Declaration of the iterator pos
string::iterator
pos;
// Display using iterator
cout << "s1= ";
for
(pos=s1.begin( );pos!=s1.end( );++pos) {
cout << *pos << " ";
}
cout <<
endl;
// Modify and display s2
cout <<
"s2= " << s2.erase(3,4)<< endl;
// Modyfy and display s3
s3=s2 + " " +
s3;
cout <<
"s3= " << s3 << endl;
// Modify and display s4
cout <<
"s4= " << s4.insert(0,"Who ") << endl;
// Reverse and display s4
reverse(s4.begin(),s4.end());
cout <<
"new s4= " << s4 << endl;
}