Version: 3.2.8
Loading...
Searching...
No Matches

#include <wx/txtstrm.h>

Detailed Description

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:

wxFileInputStream input( "mytext.txt" );
wxTextInputStream text( input );
float f2;
wxString word;
text >> i1; // read a 8 bit integer.
text >> i1 >> f2; // read a 8 bit integer followed by float.
text >> word; // read a word
This class represents data read in from a file.
Definition wfstream.h:229
String class for passing textual data to or receiving it from wxWidgets.
Definition string.h:315
This class provides functions that reads text data using an input stream, allowing you to read text,...
Definition txtstrm.h:54
unsigned char wxUint8
8 bit type (the mapping is more complex than a simple typedef and is not shown here).
Definition defs.h:1391

Library:  wxBase
Category:  Streams
See also
wxTextOutputStream

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 wxInputStreamGetInputStream () 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 an 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.
 
wxUint64 Read64 (int base=10)
 Reads a 64 bit unsigned integer from the stream.
 
wxInt64 Read64S (int base=10)
 Reads a 64 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().
 
wxTextInputStreamoperator>> (wxString &word)
 Uses ReadWord() to extract word.
 
wxTextInputStreamoperator>> (char &c)
 Extracts the next char in the stream.
 
wxTextInputStreamoperator>> (wchar_t &wc)
 Uses GetChar() to extract wc.
 
wxTextInputStreamoperator>> (wxInt16 &i)
 Uses Read16S() to extract i.
 
wxTextInputStreamoperator>> (wxInt32 &i)
 Uses Read32S() to extract i.
 
wxTextInputStreamoperator>> (wxInt64 &i)
 Uses Read64S() to extract i.
 
wxTextInputStreamoperator>> (wxUint16 &i)
 Uses Read16() to extract i.
 
wxTextInputStreamoperator>> (wxUint32 &i)
 Uses Read32() to extract i.
 
wxTextInputStreamoperator>> (wxUint64 &i)
 Uses Read64() to extract i.
 
wxTextInputStreamoperator>> (double &i)
 Uses ReadDouble() to extract i.
 
wxTextInputStreamoperator>> (float &f)
 Uses truncated result of ReadDouble() to extract f.
 
wxTextInputStreamoperator>> (__wxTextInputManip func)
 Calls func(*this).
 

Constructor & Destructor Documentation

◆ wxTextInputStream()

wxTextInputStream::wxTextInputStream ( wxInputStream & stream,
const wxString & sep = " \\ t",
const wxMBConv & conv = wxConvAuto() )

Constructs a text stream associated to the given input stream.

Parameters
streamThe underlying input stream.
sepThe initial string separator characters.
convIn Unicode build only: The encoding converter used to convert the bytes in the underlying input stream to characters.

◆ ~wxTextInputStream()

wxTextInputStream::~wxTextInputStream ( )

Destructor.

Member Function Documentation

◆ GetChar()

wxChar wxTextInputStream::GetChar ( )

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

◆ GetInputStream()

const wxInputStream & wxTextInputStream::GetInputStream ( ) const

Returns a pointer to the underlying input stream object.

Since
2.9.2

◆ operator>>() [1/12]

wxTextInputStream & wxTextInputStream::operator>> ( __wxTextInputManip func)

Calls func(*this).

◆ operator>>() [2/12]

wxTextInputStream & wxTextInputStream::operator>> ( char & c)

Extracts the next char in the stream.

◆ operator>>() [3/12]

wxTextInputStream & wxTextInputStream::operator>> ( double & i)

Uses ReadDouble() to extract i.

◆ operator>>() [4/12]

wxTextInputStream & wxTextInputStream::operator>> ( float & f)

Uses truncated result of ReadDouble() to extract f.

◆ operator>>() [5/12]

wxTextInputStream & wxTextInputStream::operator>> ( wchar_t & wc)

Uses GetChar() to extract wc.

Note
Only available in Unicode builds.

◆ operator>>() [6/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxInt16 & i)

Uses Read16S() to extract i.

◆ operator>>() [7/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxInt32 & i)

Uses Read32S() to extract i.

◆ operator>>() [8/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxInt64 & i)

Uses Read64S() to extract i.

◆ operator>>() [9/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxString & word)

Uses ReadWord() to extract word.

◆ operator>>() [10/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxUint16 & i)

Uses Read16() to extract i.

◆ operator>>() [11/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxUint32 & i)

Uses Read32() to extract i.

◆ operator>>() [12/12]

wxTextInputStream & wxTextInputStream::operator>> ( wxUint64 & i)

Uses Read64() to extract i.

◆ Read16()

wxUint16 wxTextInputStream::Read16 ( int base = 10)

Reads an unsigned 16 bit integer from the stream.

See Read8() for the description of the base parameter.

◆ Read16S()

wxInt16 wxTextInputStream::Read16S ( int base = 10)

Reads a signed 16 bit integer from the stream.

See Read8() for the description of the base parameter.

◆ Read32()

wxUint32 wxTextInputStream::Read32 ( int base = 10)

Reads a 32 bit unsigned integer from the stream.

See Read8() for the description of the base parameter.

◆ Read32S()

wxInt32 wxTextInputStream::Read32S ( int base = 10)

Reads a 32 bit signed integer from the stream.

See Read8() for the description of the base parameter.

◆ Read64()

wxUint64 wxTextInputStream::Read64 ( int base = 10)

Reads a 64 bit unsigned integer from the stream.

See Read8() for the description of the base parameter.

Since
3.1.0

◆ Read64S()

wxInt64 wxTextInputStream::Read64S ( int base = 10)

Reads a 64 bit signed integer from the stream.

See Read8() for the description of the base parameter.

Since
3.1.0

◆ Read8()

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.

◆ Read8S()

wxInt8 wxTextInputStream::Read8S ( int base = 10)

Reads a single signed byte from the stream.

See Read8() for the description of the base parameter.

◆ ReadDouble()

double wxTextInputStream::ReadDouble ( )

Reads a double (IEEE encoded) from the stream.

◆ ReadLine()

wxString wxTextInputStream::ReadLine ( )

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

◆ ReadString()

wxString wxTextInputStream::ReadString ( )
Deprecated
Use ReadLine() or ReadWord() instead.

Same as ReadLine().

◆ ReadWord()

wxString wxTextInputStream::ReadWord ( )

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

See also
SetStringSeparators()

◆ SetStringSeparators()

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.