| Version: 3.2.8

Public Member Functions | List of all members
wxTextInputStream Class Reference
Class List by Category » Streams

`#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 );
wxUint8 i1;
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
wxFileInputStream
This class represents data read in from a file.
Definition: wfstream.h:229
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
wxTextInputStream
This class provides functions that reads text data using an input stream, allowing you to read text,...
Definition: txtstrm.h:54
wxUint8
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. 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 an 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...

## 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

  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::~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.