#include <wx/txtstrm.h>
This class provides functions that reads text data using an input stream, allowing you to read text, floats, and integers.
The wxTextInputStream correctly reads text files (or streams) in DOS, Macintosh and Unix formats and reports a single newline char as a line ending.
wxTextInputStream::operator>>() is overloaded and you can use this class like a standard C++ iostream. Note, however, that the arguments are the fixed size types wxUint32, wxInt32 etc and on a typical 32-bit computer, none of these match to the "long" type (wxInt32 is defined as int on 32-bit architectures) so that you cannot use long. To avoid problems (here and elsewhere), make use of wxInt32, wxUint32 and similar types.
If you're scanning through a file using wxTextInputStream, you should check for EOF
before reading the next item (word / number), because otherwise the last item may get lost. You should however be prepared to receive an empty item (empty string / zero number) at the end of file, especially on Windows systems. This is unavoidable because most (but not all) files end with whitespace (i.e. usually a newline).
For example:
Public Member Functions | |
wxTextInputStream (wxInputStream &stream, const wxString &sep=" \t", const wxMBConv &conv=wxConvAuto()) | |
Constructs a text stream associated to the given input stream. More... | |
~wxTextInputStream () | |
Destructor. More... | |
const wxInputStream & | GetInputStream () const |
Returns a pointer to the underlying input stream object. More... | |
wxChar | GetChar () |
Reads a character, returns 0 if there are no more characters in the stream. More... | |
wxUint16 | Read16 (int base=10) |
Reads a unsigned 16 bit integer from the stream. More... | |
wxInt16 | Read16S (int base=10) |
Reads a signed 16 bit integer from the stream. More... | |
wxUint32 | Read32 (int base=10) |
Reads a 32 bit unsigned integer from the stream. More... | |
wxInt32 | Read32S (int base=10) |
Reads a 32 bit signed integer from the stream. More... | |
wxUint64 | Read64 (int base=10) |
Reads a 64 bit unsigned integer from the stream. More... | |
wxInt64 | Read64S (int base=10) |
Reads a 64 bit signed integer from the stream. More... | |
wxUint8 | Read8 (int base=10) |
Reads a single unsigned byte from the stream, given in base base. More... | |
wxInt8 | Read8S (int base=10) |
Reads a single signed byte from the stream. More... | |
double | ReadDouble () |
Reads a double (IEEE encoded) from the stream. More... | |
wxString | ReadLine () |
Reads a line from the input stream and returns it (without the end of line character). More... | |
wxString | ReadString () |
wxString | ReadWord () |
Reads a word (a sequence of characters until the next separator) from the input stream. More... | |
void | SetStringSeparators (const wxString &sep) |
Sets the characters which are used to define the word boundaries in ReadWord(). More... | |
wxTextInputStream & | operator>> (wxString &word) |
Uses ReadWord() to extract word. More... | |
wxTextInputStream & | operator>> (char &c) |
Extracts the next char in the stream. More... | |
wxTextInputStream & | operator>> (wchar_t &wc) |
Uses GetChar() to extract wc. More... | |
wxTextInputStream & | operator>> (wxInt16 &i) |
Uses Read16S() to extract i. More... | |
wxTextInputStream & | operator>> (wxInt32 &i) |
Uses Read32S() to extract i. More... | |
wxTextInputStream & | operator>> (wxInt64 &i) |
Uses Read64S() to extract i. More... | |
wxTextInputStream & | operator>> (wxUint16 &i) |
Uses Read16() to extract i. More... | |
wxTextInputStream & | operator>> (wxUint32 &i) |
Uses Read32() to extract i. More... | |
wxTextInputStream & | operator>> (wxUint64 &i) |
Uses Read64() to extract i. More... | |
wxTextInputStream & | operator>> (double &i) |
Uses ReadDouble() to extract i. More... | |
wxTextInputStream & | operator>> (float &f) |
Uses truncated result of ReadDouble() to extract f. More... | |
wxTextInputStream & | operator>> (__wxTextInputManip func) |
Calls func(*this) . More... | |
wxTextInputStream::wxTextInputStream | ( | wxInputStream & | stream, |
const wxString & | sep = " \t" , |
||
const wxMBConv & | conv = wxConvAuto() |
||
) |
Constructs a text stream associated to the given input stream.
stream | The underlying input stream. |
sep | The initial string separator characters. |
conv | In Unicode build only: The encoding converter used to convert the bytes in the underlying input stream to characters. |
wxTextInputStream::~wxTextInputStream | ( | ) |
Destructor.
wxChar wxTextInputStream::GetChar | ( | ) |
Reads a character, returns 0 if there are no more characters in the stream.
const wxInputStream& wxTextInputStream::GetInputStream | ( | ) | const |
Returns a pointer to the underlying input stream object.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxString & | word | ) |
Uses ReadWord() to extract word.
wxTextInputStream& wxTextInputStream::operator>> | ( | char & | c | ) |
Extracts the next char in the stream.
wxTextInputStream& wxTextInputStream::operator>> | ( | wchar_t & | wc | ) |
Uses GetChar() to extract wc.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxInt16 & | i | ) |
Uses Read16S() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxInt32 & | i | ) |
Uses Read32S() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxInt64 & | i | ) |
Uses Read64S() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxUint16 & | i | ) |
Uses Read16() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxUint32 & | i | ) |
Uses Read32() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | wxUint64 & | i | ) |
Uses Read64() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | double & | i | ) |
Uses ReadDouble() to extract i.
wxTextInputStream& wxTextInputStream::operator>> | ( | float & | f | ) |
Uses truncated result of ReadDouble() to extract f.
wxTextInputStream& wxTextInputStream::operator>> | ( | __wxTextInputManip | func | ) |
Calls func(*this)
.
wxUint16 wxTextInputStream::Read16 | ( | int | base = 10 | ) |
Reads a unsigned 16 bit integer from the stream.
See Read8() for the description of the base parameter.
wxInt16 wxTextInputStream::Read16S | ( | int | base = 10 | ) |
Reads a signed 16 bit integer from the stream.
See Read8() for the description of the base parameter.
wxUint32 wxTextInputStream::Read32 | ( | int | base = 10 | ) |
Reads a 32 bit unsigned integer from the stream.
See Read8() for the description of the base parameter.
wxInt32 wxTextInputStream::Read32S | ( | int | base = 10 | ) |
Reads a 32 bit signed integer from the stream.
See Read8() for the description of the base parameter.
wxUint64 wxTextInputStream::Read64 | ( | int | base = 10 | ) |
Reads a 64 bit unsigned integer from the stream.
See Read8() for the description of the base parameter.
wxInt64 wxTextInputStream::Read64S | ( | int | base = 10 | ) |
Reads a 64 bit signed integer from the stream.
See Read8() for the description of the base parameter.
wxUint8 wxTextInputStream::Read8 | ( | int | base = 10 | ) |
Reads a single unsigned byte from the stream, given in base base.
The value of base must be comprised between 2 and 36, inclusive, or be a special value 0 which means that the usual rules of C numbers are applied: if the number starts with 0x
it is considered to be in base 16, if it starts with 0 - in base 8 and in base 10 otherwise. Note that you may not want to specify the base 0 if you are parsing the numbers which may have leading zeroes as they can yield unexpected (to the user not familiar with C) results.
wxInt8 wxTextInputStream::Read8S | ( | int | base = 10 | ) |
Reads a single signed byte from the stream.
See Read8() for the description of the base parameter.
double wxTextInputStream::ReadDouble | ( | ) |
Reads a double (IEEE encoded) from the stream.
wxString wxTextInputStream::ReadLine | ( | ) |
Reads a line from the input stream and returns it (without the end of line character).
wxString wxTextInputStream::ReadString | ( | ) |
Same as ReadLine().
wxString wxTextInputStream::ReadWord | ( | ) |
Reads a word (a sequence of characters until the next separator) from the input stream.
void wxTextInputStream::SetStringSeparators | ( | const wxString & | sep | ) |
Sets the characters which are used to define the word boundaries in ReadWord().
The default separators are the space
and TAB
characters.