Users Online
· Guests Online: 45
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C++ Program to Demonstrate the use of String Class
C++ Program to Demonstrate the use of String Class
This C++ Program which demonstrates the use of string class. The program uses a special header for using string class. A ‘string’ object is created, the name of the user is taken as input to save it into the string object, the length of string object is printed and also the string object is printed by going through the object by use of iterators.
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
-
*/
-
-
#include<iostream>
-
#include<string>
-
using namespace std;
-
-
int main()
-
{
-
std::string s;
-
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!
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.