Exploring The C++ Stream Library: IO Streams
Exploring The C++ Stream Library: IO Streams
IO Streams
1 October 2008
-1-
-2-
ostream
const ostream& operator << (type) const ostream& operator << (streambuf*)
istream
const istream& operator >> (type) const istream& operator >> (streambuf*)
ofstream
ostrstream
ifstream
istrstream
1 October 2008
-3-
-4-
int i, j;
cin >> i >> j; values I and j are left unchanged
Copyright 2008 Oxford Consulting, Ltd 1 October 2008
-5-
1 October 2008
-6-
1 October 2008
-7-
1 October 2008
-8-
1 October 2008
-9-
1 October 2008
- 10 -
1 October 2008
- 11 -
1 October 2008
- 12 -
cin.eof()
Returns true if the input stream is at end of file
cin.fail()
Returns true if some input operation has failed
cin.bad()
Returns true if something has gone wrong with streambuf
1 October 2008
- 13 -
1 October 2008
- 14 -
1 October 2008
- 15 -
1 October 2008
- 16 -
1 October 2008
- 17 -
1 October 2008
- 18 -
To move within a streambuf seekp member function of ostream seekg member function of istream
1 October 2008
- 19 -
seekdir beg - seek from beginning of current file curr - seek from current position end - seek backwards from end of current file
1 October 2008
- 20 -
Useful functions in the C stdio library for doing such formatting functions sprintf and sscanf
C++ also provides similar functionality with strstreams. Must include <strstrea.h>
Copyright 2008 Oxford Consulting, Ltd 1 October 2008
- 21 -
1 October 2008
- 22 -
1 October 2008
- 23 -
1 October 2008
- 24 -
Automatic
ostrstream myString; // myString automatically allocates storage to hold the string. myString << " Bonjour la Monde << ends;;
1 October 2008
- 25 -
1 October 2008
- 26 -
storage
1 October 2008
- 27 -
Syntax
ostrstreamInstance.rdbuff()->freeze(int arg = 1); arg 0 Unfreeze the stream arg 1 (or none) Freeze the stream
1 October 2008
- 28 -
1 October 2008
- 29 -
1 October 2008
- 30 -
1 October 2008
- 31 -