#include </home/zeitlin/src/wx/github/interface/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).
以下に例を示します:
wxFileInputStream input( "mytext.txt" ); wxTextInputStream text( input ); wxUint8 i1; float f2; wxString line; text >> i1; // read a 8 bit integer. text >> i1 >> f2; // read a 8 bit integer followed by float. text >> line; // read a text line
Public Member Functions | |
wxTextInputStream (wxInputStream &stream, const wxString &sep=" \t", const wxMBConv &conv=wxConvAuto()) | |
Constructs a text stream associated to the given input stream. | |
~wxTextInputStream () | |
Destructor. | |
const wxInputStream & | GetInputStream () const |
Returns a pointer to the underlying input stream object. | |
wxChar | GetChar () |
Reads a character, returns 0 if there are no more characters in the stream. | |
wxUint16 | Read16 (int base=10) |
Reads a unsigned 16 bit integer from the stream. | |
wxInt16 | Read16S (int base=10) |
Reads a signed 16 bit integer from the stream. | |
wxUint32 | Read32 (int base=10) |
Reads a 32 bit unsigned integer from the stream. | |
wxInt32 | Read32S (int base=10) |
Reads a 32 bit signed integer from the stream. | |
wxUint8 | Read8 (int base=10) |
Reads a single unsigned byte from the stream, given in base base. | |
wxInt8 | Read8S (int base=10) |
Reads a single signed byte from the stream. | |
double | ReadDouble () |
Reads a double (IEEE encoded) from the stream. | |
wxString | ReadLine () |
Reads a line from the input stream and returns it (without the end of line character). | |
wxString | ReadString () |
wxString | ReadWord () |
Reads a word (a sequence of characters until the next separator) from the input stream. | |
void | SetStringSeparators (const wxString &sep) |
Sets the characters which are used to define the word boundaries in ReadWord(). |
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.
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.
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.