Contents Up Previous Next

wxTextInputStream

This 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 line
Include files

<wx/txtstrm.h>

Members

wxTextInputStream::wxTextInputStream
wxTextInputStream::~wxTextInputStream
wxTextInputStream::Read8
wxTextInputStream::Read8S
wxTextInputStream::Read16
wxTextInputStream::Read16S
wxTextInputStream::Read32
wxTextInputStream::Read32S
wxTextInputStream::GetChar
wxTextInputStream::ReadDouble
wxTextInputStream::ReadLine
wxTextInputStream::ReadString
wxTextInputStream::ReadWord
wxTextInputStream::SetStringSeparators


wxTextInputStream::wxTextInputStream

wxTextInputStream(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::Read8

wxUint8 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::Read8S

wxInt8 Read8S(int base = 10)

Reads a single signed byte from the stream.

See wxTextInputStream::Read8 for the description of the base parameter.


wxTextInputStream::Read16

wxUint16 Read16(int base = 10)

Reads a unsigned 16 bit integer from the stream.

See wxTextInputStream::Read8 for the description of the base parameter.


wxTextInputStream::Read16S

wxInt16 Read16S(int base = 10)

Reads a signed 16 bit integer from the stream.

See wxTextInputStream::Read8 for the description of the base parameter.


wxTextInputStream::Read32

wxUint32 Read32(int base = 10)

Reads a 32 bit unsigned integer from the stream.

See wxTextInputStream::Read8 for the description of the base parameter.


wxTextInputStream::Read32S

wxInt32 Read32S(int base = 10)

Reads a 32 bit signed integer from the stream.

See wxTextInputStream::Read8 for the description of the base parameter.


wxTextInputStream::GetChar

wxChar GetChar()

Reads a character, returns 0 if there are no more characters in the stream.


wxTextInputStream::ReadDouble

double ReadDouble()

Reads a double (IEEE encoded) from the stream.


wxTextInputStream::ReadLine

wxString ReadLine()

Reads a line from the input stream and returns it (without the end of line character).


wxTextInputStream::ReadString

wxString ReadString()

NB: This method is deprecated, use ReadLine or ReadWord instead.

Same as ReadLine.


wxTextInputStream::ReadWord

wxString ReadWord()

Reads a word (a sequence of characters until the next separator) from the input stream.

See also

SetStringSeparators


wxTextInputStream::SetStringSeparators

void 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.