Standard Input / Output
Standard output
Insertion operator (<<)Standard input
#include <iostream>Formatting output
...
cout << "one" << "two" << endl;
Setting and unsetting options
Options
- ios::setf()
- ios::unsetf()
Manipulators
- ios::skipws, ios::left, ...
Zero parametersExamples
One parameter
- endl // Endline
- ends // End-of-string
- dec, oct, hex
- flush
- ws // Skip whitespace
- setw(x) // Set field width
- setfill(x) // Set fill char
- setprecision(x) // Number of digits after the decimal point
- setiosflags(x), resetiosflags(x)
#include <iostream>
...
cout << dec << 123 << hex << 123 << endl;
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
cout << 12.3456 << endl;
Extraction operator (>>)
#include <iostream>get / getline
...
cin >> x >> y;
#include <iostream>
...
cin >> get(ch) >> get(str, length);
cin.getline(str, length);
// Read each line.
while (!cin.getline(str, length).eof()) { ... }
// Test for input error.
if (!cin) { ... }
if (cin.fail()) { ... }
if (!cin.good()) { ... }