#include using namespace std; int main() { stringstream ss("SS"); ostringstream os("OS"); istringstream is("IS"); ss.get(); cout << "1:" << ss << endl; cout << "2:" << ss.str() << endl; cout << "3:" << ss.rdbuf() << endl; cout << "4:" << ss.rdbuf()->str() << endl; is.get(); cout << "1:" << is << endl; cout << "2:" << is.str() << endl; cout << "3:" << is.rdbuf() << endl; cout << "4:" << is.rdbuf()->str() << endl; //os.get(); // cannot be called on ostringstream cout << "1:" << os << endl; cout << "2:" << os.str() << endl; //cout << "3:" << os.rdbuf() << endl; cout << "4:" << os.rdbuf()->str() << endl; cout << "---" << endl; stringstream ss2; ostringstream os2("OS"); istringstream is2("IS"); char my1[]="SS2"; char my2[]="OS2"; char my3[]="IS2"; ss2.rdbuf()->pubsetbuf(my1,3); os2.rdbuf()->pubsetbuf(my2,3); is2.rdbuf()->pubsetbuf(my3,3); ss2.get(); cout << "1:" << ss2 << endl; cout << "2:" << ss2.str() << endl; cout << "3:" << ss2.rdbuf() << endl; cout << "4:" << ss2.rdbuf()->str() << endl; is2.get(); cout << "1:" << is2 << endl; cout << "2:" << is2.str() << endl; cout << "3:" << is2.rdbuf() << endl; cout << "4:" << is2.rdbuf()->str() << endl; //os2.get(); // cannot be called on ostringstream cout << "1:" << os2 << endl; cout << "2:" << os2.str() << endl; //cout << "3:" << os.rdbuf() << endl; cout << "4:" << os2.rdbuf()->str() << endl; }