Here is the source code of the C++ program which illustrates use of input string stream. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to illustrate use of input string stream
using namespace std;
void print(const string& places)
int count = 0;
while(is >> s)
cout << (++count) << ". " << s << endl;
if(count > 0)
cout << "You have visited " << count << " places!" << endl;
cout << "You went nowhere!" << endl;
cout << "Enter the places you visited : ";
cout << "Printing the places you visited :-" << endl;
$ a.out Enter the places you visited : USA Germany London India Printing the places you visited :- 1. USA 2. Germany 3. London 4. India You have visited 4 places!
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.