Module: Essential Tools Module Group: Virtual Stream Classes
RWpostreamRWvostreamRWvios
flush() operator void*() operator<<() |
precision() put() putString() |
RWpostream() std() ~RWpostream() |
#include <rw/pstream.h> // Construct an RWpostream, using cout's streambuf: RWpostream pstr(cout) ;
Class RWpostream specializes the abstract base class RWvostream to store variables in a portable (printable) ASCII format. The results can be restored by using its counterpart RWpistream.
You can think of RWpistream and RWpostream as an ASCII veneer over an associated streambuf which are responsible for formatting variables and escaping characters such that the results can be interchanged between any machines. As such, they are slower than their binary counterparts RWbistream and RWbostream which are more machine dependent. Because RWpistream and RWpostream retain no information about the state of their associated std::streambufs, their use can be freely exchanged with other users of the streambuf (such as std::istream or std::ifstream).
The goal of class RWpostream and RWpistream is to store variables using nothing but printable ASCII characters. Hence, nonprintable characters must be converted into an external representation where they can be recognized. Furthermore, other characters may be merely bit values (a bit image, for example), having nothing to do with characters as symbols. For example,
RWpostream pstrm(cout); char c = '\n'; pstr << c; // Stores "newline" pstr.put(c); // Stores the number 10.
The expression "pstr << c"treats c as a symbol for a newline, an unprintable character. The expression "pstr.put(c)" treats c as the literal number "10".
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.
RWpostream can be interrogated as to the stream state using member functions good(), bad(), eof(), precision(), etc.
None
See RWpistream for an example of how to read back in the results of this program.
#include <iostream> #include <fstream> #include <rw/pstream.h> int main() { // Open an output file std::ofstream fstr ("data.dat"); // Construct a RWpostream from it RWpostream pstr (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 RWpostream!\n"; // Store a float & double pstr << i << f << d; return 0; }
Program output:
An integer, a float and a double sent out on a RWpostream!
RWpostream(streambuf* s);
Initialize an RWpostream from the streambuf s.
RWpostream(ostream& str);
Initialize an RWpostream from the std::streambuf associated with the output stream str.
virtual ~RWpostream();
Empty Destructor.
virtual RWvostream& operator<<(const char* s);
Redefined from class RWvostream. Store the character string starting at s to the output stream using a portable format. 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 using a portable format. The 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 using a portable format. Note that c is treated as a character, not a number. This member attempts to preserve the symbolic characters values transmitted over the stream
virtual RWvostream& operator<<(wchar_t wc);
Redefined from class RWvostream. Store the wide char wc to the output stream using a portable format. Note that wc is treated as a character, not a number.
virtual RWvostream& operator<<(unsigned char c);
Redefined from class RWvostream. Store the unsigned char c to the output stream using a portable format. Note that c is treated as a character, not a number.
virtual RWvostream& operator<<(double d);
Redefined from class RWvostream. Store the double d to the output stream using a portable format.
virtual RWvostream& operator<<(long double d);
Redefined from class RWvostream. Store the long double d to the output stream using a portable format. 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 using a portable format.
virtual RWvostream& operator<<(int i);
Redefined from class RWvostream. Store the int i to the output stream using a portable format.
virtual RWvostream& operator<<(unsigned int i);
Redefined from class RWvostream. Store the unsigned int i to the output stream using a portable format.
virtual RWvostream& operator<<(long l);
Redefined from class RWvostream. Store the long l to the output stream using a portable format.
virtual RWvostream& operator<<(long long l);
Redefined from class RWvostream. Store the long long l to the output stream using a portable format. 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 using a portable format.
virtual RWvostream& operator<<(unsigned long long l);
Redefined from class RWvostream. Store the unsigned long long l to the output stream using a portable format. Note: This operator function is only available if your compiler supports the unsigned long long l type.
virtual RWvostream& operator<<(short s);
Redefined from class RWvostream. Store the short s to the output stream using a portable format.
virtual RWvostream& operator<<(unsigned short s);
Redefined from class RWvostream. Store the unsigned short s to the output stream using a portable format.
operator void*();
Inherited via RWvostream from RWvios.
virtual RWvostream& flush();
Send the contents of the stream buffer to output immediately.
int precision() const;
Returns the currently set precision used for writing float and double data. At construction, the precision is set to RW_DEFAULT_PRECISION by a compiler characterization.
int precision(int p);
Changes the precision used for writing float and double data. Returns the previously set precision. At construction, the precision is set to RW_DEFAULT_PRECISION by a compiler characterization.
virtual RWvostream& put(char c);
Redefined from class RWvostream. Store the char c to the output stream, preserving its value using a portable format. This member only preserves ASCII numerical codes, not the corresponding character symbol.
virtual RWvostream& put(wchar_t wc);
Redefined from class RWvostream. Store the wide character wc to the output stream, preserving its value using a portable format.
virtual RWvostream& put(unsigned char c);
Redefined from class RWvostream. Store the unsigned char c to the output stream, preserving its value using a portable format.
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, preserving their values using a portable format. Note that the characters will be treated as literal numbers (i.e., not as a character string).
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, preserving their values using a portable format. Note that the characters will be treated as literal numbers (i.e., not as a character string).
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 using a portable format. The characters should be treated as literal numbers (i.e., not as a character string).
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 using a portable format.
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 using a portable format.
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 using a portable format.
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 using a portable format.
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 using a portable format.
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 using a portable format. Note: This operator function is only available if your compiler supports the 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 using a portable format.
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 using a portable format. Note: This operator function is only available if your compiler supports the 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 using a portable format.
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 using a portable format.
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 using a portable format. Note: This operator function is only available if your compiler supports the long double type.
virtual RWvostream& putString(const char*s, size_t N);
Store the character string, including embedded nulls, starting at s to the output string.
std::ostream& std (); const std::ostream& std () const;
Returns a reference to the underlying C++ Standard Library data type. The reference can be used to access the functionality exposed via std::ostream interface.
© 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.