Module: Essential Tools Module Group: Virtual Stream Classes
RWpistreamRWvistreamRWvios
#include <rw/pstream.h> RWpistream pstr(cin); // Construct an RWpistream, // using cin's streambuf
Class RWpistream specializes the abstract base class RWvistream to restore variables stored in a portable ASCII format by RWpostream.
You can think of RWpistream and RWpostream as an ASCII veneer over an associated std::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 streambufs, their use can be freely exchanged with other users of the streambuf (such as std::istream or std::ifstream).
RWpistream can be interrogated as to the stream state using member functions good(), bad(), eof(), etc.
None
See RWpostream for an example of how to create an input stream for this program.
#include <iostream> #include <fstream> #include <rw/pstream.h> int main() { // Open an input file std::ifstream fstr ("data.dat"); // Construct RWpistream from it RWpistream pstr (fstr); int i; float f; double d; // Restore an int that was stored in binary if(!(pstr >> i)) { std::cout << "Run postream.exe first!\n"; } else { // Restore a float & double pstr >> f >> d; std::cout << "The integer: " << i << std::endl; std::cout << "The float: " << f << std::endl; std::cout << "The double: " << d << std::endl; } return 0; }
Program output:
The integer: 5 The float: 22.1 The double: -0.05
RWpistream(streambuf* s);
Initialize an RWpistream from the streambuf s.
RWpistream(istream& str);
Initialize an RWpistream using the std::streambuf associated with the istream str.
virtual ~RWpistream();
Empty destructor.
virtual RWvistream& operator>>(char& c);
Redefined from class RWvistream. Get the next character from the input stream and store it in c. This member attempts to preserve the symbolic characters values transmitted over the stream.
virtual RWvistream& operator>>(wchar_t& wc);
Redefined from class RWvistream. Get the next wide char from the input stream and store it in wc.
virtual RWvistream& operator>>(double& d);
Redefined from class RWvistream. Get the next double from the input stream and store it in d.
virtual RWvistream& operator>>(long double& d);
Redefined from class RWvistream. Get the next long double from the input stream and store it in d. Note: This operator function is only available if your compiler supports the long double type.
virtual RWvistream& operator>>(float& f);
Redefined from class RWvistream. Get the next float from the input stream and store it in f.
virtual RWvistream& operator>>(int& i);
Redefined from class RWvistream. Get the next int from the input stream and store it in i.
virtual RWvistream& operator>>(long& l);
Redefined from class RWvistream. Get the next long from the input stream and store it in l.
virtual RWvistream& operator>>(long long& l);
Redefined from class RWvistream. Get the next long long from the input stream and store it in l. Note: This operator function is only available if your compiler supports the long long type.
virtual RWvistream& operator>>(short& s);
Redefined from class RWvistream. Get the next short from the input stream and store it in s.
virtual RWvistream& operator>>(unsigned char& c);
Redefined from class RWvistream. Get the next unsigned char from the input stream and store it in c.
virtual RWvistream& operator>>(unsigned short& s);
Redefined from class RWvistream. Get the next unsigned short from the input stream and store it in s.
virtual RWvistream& operator>>(unsigned int& i);
Redefined from class RWvistream. Get the next unsigned int from the input stream and store it in i.
virtual RWvistream& operator>>(unsigned long& l);
Redefined from class RWvistream. Get the next unsigned long from the input stream and store it in l.
virtual RWvistream& operator>>(unsigned long long& l);
Redefined from class RWvistream. Get the next unsigned long long from the input stream and store it in l. Note: This operator function is only available if your compiler supports the unsigned long long type.
operator void*();
Inherited via RWvistream from RWvios.
virtual int get();
Redefined from class RWvistream. Get and return the next character from the input stream. Returns EOF if end of file is encountered.
virtual RWvistream& get(char& c);
Redefined from class RWvistream. Get the next char and store it in c. This member only preserves ASCII numerical codes, not the corresponding character symbol.
virtual RWvistream& get(wchar_t& wc);
Redefined from class RWvistream. Get the next wide char and store it in wc.
virtual RWvistream& get(unsigned char& c);
Redefined from class RWvistream. Get the next unsigned char and store it in c.
virtual RWvistream& get(char* v, size_t N);
Redefined from class RWvistream. Get a vector of chars and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit. Note that this member preserves ASCII numerical codes, not their corresponding character values. If you wish to restore a character string, use the function getString(char*, size_t).
virtual RWvistream& get(wchar_t* v, size_t N);
Redefined from class RWvistream. Gets a vector of wide chars and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit. Note that this member preserves ASCII numerical codes, not their corresponding character values. If you wish to restore a character string, use the function getString(char*, size_t).
virtual RWvistream& get(double* v, size_t N);
Redefined from class RWvistream. Gets a vector of doubles and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(long double* v, size_t N);
Redefined from class RWvistream. Get a vector of long doubles and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit. Note: This operator function is only available if your compiler supports the long double type.
virtual RWvistream& get(float* v, size_t N);
Redefined from class RWvistream. Get a vector of floats and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(int* v, size_t N);
Redefined from class RWvistream. Get a vector of ints and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(long* v, size_t N);
Redefined from class RWvistream. Get a vector of longs and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(long long* v, size_t N);
Redefined from class RWvistream. Get a vector of long longs and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit. Note: This operator function is only available if your compiler supports the long long type.
virtual RWvistream& get(short* v, size_t N);
Redefined from class RWvistream. Get a vector of shorts and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(unsigned char* v, size_t N);
Redefined from class RWvistream. Get a vector of unsigned chars and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit. Note that this member preserves ASCII numerical codes, not their corresponding character values. If you wish to restore a character string, use the function getString(char*, size_t).
virtual RWvistream& get(unsigned short* v, size_t N);
Redefined from class RWvistream. Get a vector of unsigned shorts and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(unsigned int* v, size_t N);
Redefined from class RWvistream. Get a vector of unsigned ints and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(unsigned long* v, size_t N);
Redefined from class RWvistream. Get a vector of unsigned longs and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit.
virtual RWvistream& get(unsigned long long* v, size_t N);
Redefined from class RWvistream. Get a vector of unsigned long longs and store them in the array beginning at v. If the restore operation stops prematurely, because there are no more data available on the stream, because an exception is thrown, or for some other reason; get stores what has already been retrieved from the stream into v, and sets the failbit. Note: This operator function is only available if your compiler supports the unsigned long long type.
virtual RWvistream& getString(char* s, size_t N);
Redefined from class RWvistream. Restores a character string from the input stream and stores it in the array beginning at s. The function stops reading at the end of the string or after N-1 characters, whichever comes first. If N-1 characters have been read and the Nth character is not the string terminator, then the failbit of the stream will be set. In either case, the string will be terminated with a null byte. If the input stream has been corrupted, then an exception of type RWExternalErr will be thrown.
virtual RWvistream& getString(wchar_t* ws, size_t N);
Redefined from class RWvistream. Restores a character string from the input stream and stores it in the array beginning at ws. The function stops reading at the end of the string or after N-1 characters, whichever comes first. If N-1 characters have been read and the Nth character is not the string terminator, then the failbit of the stream will be set. In either case, the string will be terminated with a null byte. If the input stream has been corrupted, then an exception of type RWExternalErr will be thrown.
std::istream& std(); const std::istream& 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::istream 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.