Module: Essential Tools Module Group: Virtual Stream Classes
RWvostreamRWvios RWbostream std::ios
#include <rw/bstream.h> // Construct an RWbostream, using cout's streambuf: RWbostream bstr(std::cout);
Class RWbostream specializes the abstract base class RWvostream to store variables in binary format. The results can be restored by using its counterpart RWbistream.
You can think of it as a binary veneer over an associated std::streambuf. Because the RWbostream retains no information about the state of its associated streambuf, its use can be freely exchanged with other users of the streambuf (such as std::ostream or std::ofstream).
Note that variables should not be separated with white space. Such white space would be interpreted literally and would have to be read back in as a character string.
RWbostream can be interrogated as to the stream state using member functions good(), bad(), eof(), etc.
None
See RWbistream for an example of how the file "data.dat" might be read back in.
#include <iostream> #include <fstream> #include <rw/bstream.h> int main() { // Open an output file std::ofstream fstr ("data.dat"); // Construct a RWbostream from it RWbostream bstr (fstr); int i = 5; float f = 22.1f; double d = -0.05; std::cout << "An integer, a float and a double sent out on a RWbostream!\n"; // Store a float & double bstr << i << f << d; return 0; }
Program output:
An integer, a float and a double sent out on an RWbostream!
RWbostream(streambuf* s);
Construct an RWbostream from the streambuf s. For DOS, the streambuf must have been opened in binary mode.
RWbostream(ostream& str);
Construct an RWbostream from the streambuf associated with the output stream str. For DOS, the streambuf must have been opened in binary mode. This can be done by specifying ios::binary as part of the second argument to the constructor for an std::ofstream. Using the example above, the line to create the ofstream would read, ofstream fstr("data.dat", ios::out | ios::binary); where the "|" is the binary OR operator.
virtual ~RWvostream();
Empty destructor.
virtual RWvostream& operator<<(const char* s);
Redefined from class RWvostream. Store the character string starting at s to the output stream in binary. The character string is expected to be null terminated.
virtual RWvostream& operator<<(const wchar_t* ws);
Redefined from class RWvostream. Store the wide character string starting at ws to the output stream in binary. The wide character string is expected to be null terminated.
virtual RWvostream& operator<<(char c);
Redefined from class RWvostream. Store the char c to the output stream in binary.
virtual RWvostream& operator<<(wchar_t wc);
Redefined from class RWvostream. Store the wide char wc to the output stream in binary.
virtual RWvostream& operator<<(unsigned char c);
Redefined from class RWvostream. Store the unsigned char c to the output stream in binary.
virtual RWvostream& operator<<(double d);
Redefined from class RWvostream. Store the double d to the output stream in binary.
virtual RWvostream& operator<<(long double d);
Redefined from class RWvostream. Store the long double d to the output stream in binary. Note: This operator function is only available if your compiler supports the long double d type.
virtual RWvostream& operator<<(float f);
Redefined from class RWvostream. Store the float f to the output stream in binary.
virtual RWvostream& operator<<(int i);
Redefined from class RWvostream. Store the int i to the output stream in binary.
virtual RWvostream& operator<<(unsigned int i);
Redefined from class RWvostream. Store the unsigned int i to the output stream in binary.
virtual RWvostream& operator<<(long l);
Redefined from class RWvostream. Store the long l to the output stream in binary.
virtual RWvostream& operator<<(long long l);
Redefined from class RWvostream. Store the long long l to the output stream in binary. Note: This operator function is only available if your compiler supports the long long l type.
virtual RWvostream& operator<<(unsigned long l);
Redefined from class RWvostream. Store the unsigned long l to the output stream in binary.
virtual RWvostream& operator<<(unsigned long long);
Redefined from class RWvostream. Store the unsigned long long to the output stream in binary. Note: This operator function is only available if your compiler supports the unsigned long long type.
virtual RWvostream& operator<<(short s);
Redefined from class RWvostream. Store the short s to the output stream in binary.
virtual RWvostream& operator<<(unsigned short s);
Redefined from class RWvostream. Store the unsigned short s to the output stream in binary.
operator void*();
Inherited via RWvostream from RWvios.
virtual RWvostream& flush();
Send the contents of the stream buffer to output immediately.
virtual RWvostream& put(char c);
Redefined from class RWvostream. Store the char c to the output stream.
virtual RWvostream& put(wchar_t wc);
Redefined from class RWvostream. Store the wide character wc to the output stream.
virtual RWvostream& put(unsigned char c);
Redefined from class RWvostream. Store the unsigned char c to the output stream.
virtual RWvostream& put(const char* p, size_t N);
Redefined from class RWvostream. Store the vector of chars starting at p to the output stream in binary.
virtual RWvostream& put(const wchar_t* p, size_t N);
Redefined from class RWvostream. Store the vector of wide chars starting at p to the output stream in binary.
virtual RWvostream& put(const unsigned char* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned chars starting at p to the output stream in binary.
virtual RWvostream& put(const short* p, size_t N);
Redefined from class RWvostream. Store the vector of shorts starting at p to the output stream in binary.
virtual RWvostream& put(const unsigned short* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned shorts starting at p to the output stream in binary.
virtual RWvostream& put(const int* p, size_t N);
Redefined from class RWvostream. Store the vector of ints starting at p to the output stream in binary.
virtual RWvostream& put(const unsigned int* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned ints starting at p to the output stream in binary.
virtual RWvostream& put(const long* p, size_t N);
Redefined from class RWvostream. Store the vector of longs starting at p to the output stream in binary.
virtual RWvostream& put(const long long* p, size_t N);
Redefined from class RWvostream. Store the vector of long longs starting at p to the output stream in binary. Note: This operator function is only available if your compiler supports the const long long type.
virtual RWvostream& put(const unsigned long* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned longs starting at p to the output stream in binary.
virtual RWvostream& put(const unsigned long long* p, size_t N);
Redefined from class RWvostream. Store the vector of unsigned long longs starting at p to the output stream in binary. Note: This operator function is only available if your compiler supports the const unsigned long long type.
virtual RWvostream& put(const float* p, size_t N);
Redefined from class RWvostream. Store the vector of floats starting at p to the output stream in binary.
virtual RWvostream& put(const double* p, size_t N);
Redefined from class RWvostream. Store the vector of doubles starting at p to the output stream in binary.
virtual RWvostream& put(const long double* p, size_t N);
Redefined from class RWvostream. Store the vector of long doubles starting at p to the output stream in binary. Note: This operator function is only available if your compiler supports the const long double type.
virtual RWvostream& putString(const char* p, size_t N);
Redefined from class RWvostream. Data is formatted as a string containing N characters.
virtual RWvostream& putString(const char*s, size_t N);
Store the character string, including embedded nulls, starting at s to the output string.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.