Stream Input/Output
ios
/ \
/ \
istream ostream
/ \ / \
/ \ / \
ifstream iostream ofstream
|
|
fstream
Iostream Library
- <iomanip.h>
- <fstream.h>
- <strstream.h>
- <stdiostream.h>
Stream Output
Stream Extraction >>
Stream Manipulators
Parameter
Header File Function Type Effect
--------------------------------------------------------------------------------------------
iostream.h endl None Terminate the current output line
iomanip.h setw(n) int Sets field width to n
iomanip.h setprecision(n) int Set floating point precision to n digits
--------------------------------------------------------------------------------------------
Stream formatting funcions
Stream Format States
ios::skipws
ios::left
ios::right
ios::internal
ios::dec
ios::oct
ios::hex
ios::showbase
ios::showpoint
ios::uppercase
ios::showpos
ios::scientific
ios::fixed
Stream Input
Stream Insertion <<
Get and Getline Member Functions
- c = cin.get();
- cin.get(ch);
- cin.get(buffer, SIZE); // get(buffer, SIZE, '\n')
- cin.getline(buffer, SIZE); // get(buffer, SIZE, '\n')
Streams and Files
Examples
- lines.cc (use getline)
- lines2.cc (use get)
- wcount2.cc
- wcount.cc (use string stream)
- readnums.cc