string stream classes in action. : String stream « File « C++






string stream classes in action.

  
#include <iostream>
#include <sstream>

using namespace std;

int main()
{
  char ch;
  ostringstream strout;

  strout << 10 << " " << -20 << " " << 30.2 << "\n";
  strout << "This is a test.";

  cout << strout.str() << endl;

  strout << "\nThis is some more output.\n";

  cout << "Use an input string stream called strin.\n";

  istringstream strin(strout.str());

  cout << "Here are the current contents of strin via get():\n";
  do {
    ch = strin.get();
    if(!strin.eof()) cout << ch;
  } while(!strin.eof());

  stringstream strinout;

  strinout << 10 << " + " << 12 << " is " << 10+12 << endl;

  do {
    ch = strinout.get();
    if(!strinout.eof()) cout << ch;
  } while(!strinout.eof());
  cout << endl;

  strinout.clear();
  strinout << "More output to strinout.\n";

  do {
    ch = strinout.get();
    if(!strinout.eof()) cout << ch;
  } while(!strinout.eof());
}
  
    
  








Related examples in the same category

1.Demonstrate string streams. Demonstrate string streams.
2.create string stream for input/output