<ostream><<to write to a stream objectcoutis stdout,cerris stderr- Chaining
<<is possible:cout << a << b;
<istream>>>to write to a stream objectcinis stdin. Whitespace is stripped by defaultgetlineto read entire lines
- stream objects hold state
- Testing an object (in an
iforfor) returns results depending on the state - This allows us to iterate over streams elegantly:
while(is >> i) { … }
- We can overload
<<and>>to work with user-defined types - There are methods for setting the state of a stream (
failbit,badbit)
- Manipulators can be used for formatting
cout << hex << 16;- To manipulate the entire stream, there are special methods, e.g.
cout.precision(5)
- Similary, there are streams for files. Nothing surprising here
<sstream>, stringstreamfor streaming strings- (Note: This seems to be just for convenience, not performance)
template<typename T=string>for setting a default