|
explicit ostream (streambuf * sb);
Construct object
Constructs an object, assigning initial values to the base class by calling the inherited member ios::init with sb as parameter.
Parameters
- sb
- pointer to a streambuf object, which is set as the associated stream buffer for the object.
Return Value
None (constructor).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// ostream constructor
#include <iostream>
#include <fstream>
using namespace std;
int main () {
filebuf fb;
fb.open ("test.txt",ios::out);
ostream os(&fb);
os << "Test sentence\n";
fb.close();
return 0;
}
|
This code uses a filebuf object (derived from streambuf) to open the file test.txt. The buffer is then passed as parameter to the ostream constructor, associating it to the stream.
Objects of class ostream are seldom constructed directly. Generally some derived class is used (like the standard ones ofstream and ostringstream).
Basic template member declaration
( basic_ostream<charT,traits> )
|
explicit basic_ostream ( basic_streambuf<charT,traits>* sb );
|
See also
ios_base::Init | Initialize standard stream objects (public member class) |
|