Creates a stream and associates it with a char array for output.
ostrstream(); ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
The ostrstream class is overloaded for association with a pre allocated array or for dynamic allocation.
When using an ostrstream object the user must supply a null character for termination. When storing a string which is already null terminated that null terminator is stripped off to allow for appending.
#include <iostream> #include <strstream> int main() { ostrstream out; out << "Ask the teacher anything you want to know" << ends; istream inOut(out.rdbuf() ); char c; while( inOut.get(c) ) cout.put(c); return 0; }
Result:
Ask the teacher anything you want to know