Mega Code Archive

 
Categories / C++ / File
 

Display the contents of strin via calls to get()

#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";   // use the contents of strout to create strin:   istringstream strin(strout.str());   // Display the contents of strin via calls to get().   cout << "Here are the current contents of strin via get():\n";   do {     ch = strin.get();     if(!strin.eof()) cout << ch;   } while(!strin.eof()); }