RWpostreamRWvostreamRWvios
Member Functions | |||
flush() operator void*() |
operator<<() precision() |
put() putString() |
#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. They 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 streambufs, their use can be freely exchanged with other users of the streambuf, such as istream or ifstream.
The goal of class RWpostream and RWpistream is to store variables using nothing but printable ASCII characters. Nonprintable characters must be converted into an external representation in which they can be recognized. Other characters may be merely bit values, like a bit image, which have 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:Variables should not be separated with white space. Such white space is interpreted literally and must be read back in as a character string.
RWpostream can be interrogated as to the stream state using member functions good(), bad(), eof(), precision(), and so on.
See RWpistream for an example of how to read back in the results of this program. The symbol o is intended to represent a control-G, or bell.
#include <rw/pstream.h> main(){ // Construct an RWpostream to use standard output: RWpostream pstr(cout); int i = 5; float f = 22.1; double d = -0.05; char string[] = "A string with\ttabs,\nnewlines and a o bell."; pstr << i; // Store an int in binary pstr << f << d; // Store a float & double pstr << string; // Store a string }
Program output:
5
22.1
-0.05
"A string with\ttabs,\nnewlines and a \x07 bell."
RWpostream(streambuf* s);
Initializes an RWpostream from the streambuf s.
RWpostream(ostream& str);
Initializes an RWpostream from the streambuf associated with the output stream str.
virtual ~RWvostream();
This virtual destructor allows specializing classes to deallocate any resources that they have allocated.
virtual RWvostream& operator<<(const char* s);
Redefined from class RWvostream. Stores 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. Stores 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. Stores 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. Stores 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. Stores 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. Stores the double d to the output stream using a portable format.
virtual RWvostream& operator<<(float f);
Redefined from class RWvostream. Stores the float f to the output stream using a portable format.
virtual RWvostream& operator<<(int i);
Redefined from class RWvostream. Stores the int i to the output stream using a portable format.
virtual RWvostream& operator<<(unsigned int i);
Redefined from class RWvostream. Stores the unsigned int i to the output stream using a portable format.
virtual RWvostream& operator<<(long l);
Redefined from class RWvostream. Stores the long l to the output stream using a portable format.
virtual RWvostream& operator<<(unsigned long l);
Redefined from class RWvostream. Stores the unsigned long l to the output stream using a portable format.
virtual RWvostream& operator<<(short s);
Redefined from class RWvostream. Stores the short s to the output stream using a portable format.
virtual RWvostream& operator<<(unsigned short s);
Redefined from class RWvostream. Stores the unsigned short s to the output stream using a portable format.
operator void*();
Inherited via RWvostream from RWvios.
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, which is defined in compiler.h.
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, which is defined in compiler.h.
virtual RWvostream& flush();
Sends the contents of the stream buffer to output immediately.
virtual RWvostream& put(char c);
Redefined from class RWvostream. Stores 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 symbols.
virtual RWvostream& put(wchar_t wc);
Redefined from class RWvostream. Stores 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. Stores 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. Stores the vector of chars starting at p to the output stream, preserving their values using a portable format. Note that the characters are treated as literal numbers, not as a character string.
virtual RWvostream& put(const wchar_t* p, size_t N);
Redefined from class RWvostream. Stores the vector of wide chars starting at p to the output stream, preserving their values using a portable format. Note that the characters are treated as literal numbers, not as a character string.
virtual RWvostream& put(const unsigned char* p, size_t N);
Redefined from class RWvostream. Stores the vector of unsigned chars starting at p to the output stream using a portable format. The characters should be treated as literal numbers, not as a character string.
virtual RWvostream& put(const short* p, size_t N);
Redefined from class RWvostream. Stores 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. Stores 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. Stores 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. Stores 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. Stores the vector of longs starting at p to the output stream using a portable format.
virtual RWvostream& put(const unsigned long* p, size_t N);
Redefined from class RWvostream. Stores the vector of unsigned longs starting at p to the output stream using a portable format.
virtual RWvostream& put(const float* p, size_t N);
Redefined from class RWvostream. Stores 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. Stores the vector of doubles starting at p to the output stream using a portable format.
virtual RWvostream& putString(const char*s, size_t N);
Stores the character string, including embedded nulls, starting at s to the output string.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.