Here is source code of the C++ program which demonstrates the use of string class. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Demonstrate use of String Class
using namespace std;
cout << "Enter your first name : ";
cin >> s;
cout << "The length of your name is " << s.length() << endl;
cout << "Nice to meet you ";
/* Printing using const_iterator */
for (std::string::const_iterator i = s.begin(); i != s.end(); i++)
cout << *i;
cout << "!" << endl;
$ g++ main.cpp $ ./a.out Enter your first name : George The length of your name is 6 Nice to meet you George!
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.