<ostream>
<<
to write to a stream objectcout
is stdout,cerr
is stderr- Chaining
<<
is possible:cout << a << b;
<istream>
>>
to write to a stream objectcin
is stdin. Whitespace is stripped by defaultgetline
to read entire lines
- stream objects hold state
- Testing an object (in an
if
orfor
) 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>, stringstream
for streaming strings- (Note: This seems to be just for convenience, not performance)
template<typename T=string>
for setting a default