wxtextinputstreamthis class provides functions that read text datas using an input stream. so, you can read text floats, 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. 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:
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 lineinclude files <wx/txtstrm.h> members
wxtextinputstream::wxtextinputstream
wxtextinputstream::wxtextinputstreamwxtextinputstream(wxinputstream& stream, const wxstring& sep=" \t", wxmbconv& conv = wxconvutf8 ) constructs a text stream associated to the given input stream. parameters stream
sep
conv
wxtextinputstream::~wxtextinputstream~wxtextinputstream() destroys the wxtextinputstream object.
wxtextinputstream::read8wxuint8 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.
wxtextinputstream::read8swxint8 read8s(int base = 10) reads a single signed byte from the stream. see wxtextinputstream::read8 for the description of the base parameter.
wxtextinputstream::read16wxuint16 read16(int base = 10) reads a unsigned 16 bit integer from the stream. see wxtextinputstream::read8 for the description of the base parameter.
wxtextinputstream::read16swxint16 read16s(int base = 10) reads a signed 16 bit integer from the stream. see wxtextinputstream::read8 for the description of the base parameter.
wxtextinputstream::read32wxuint32 read32(int base = 10) reads a 32 bit unsigned integer from the stream. see wxtextinputstream::read8 for the description of the base parameter.
wxtextinputstream::read32swxint32 read32s(int base = 10) reads a 32 bit signed integer from the stream. see wxtextinputstream::read8 for the description of the base parameter.
wxtextinputstream::getcharwxchar getchar() reads a character, returns 0 if there are no more characters in the stream.
wxtextinputstream::readdoubledouble readdouble() reads a double (ieee encoded) from the stream.
wxtextinputstream::readlinewxstring readline() reads a line from the input stream and returns it (without the end of line character).
wxtextinputstream::readstringwxstring readstring() nb: this method is deprecated, use readline or readword instead. same as readline.
wxtextinputstream::readwordwxstring readword() reads a word (a sequence of characters until the next separator) from the input stream. see also
wxtextinputstream::setstringseparatorsvoid 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.
|