Tsallaka zuwa abun ciki
Justice Tech School

Input and Output Streams

cout prints and cin reads. <iomanip> formats numbers with setw, setprecision and fixed. getline reads a whole line. stringstream parses text.

Example
#include <iomanip>
#include <sstream>
cout << fixed << setprecision(2) << 3.14159 << "\n";
cout << setw(6) << 42 << "|" << left << setw(6) << "ab" << "|\n";
istringstream in("10 20 abc");
int a, b; string w;
in >> a >> b >> w;
cout << a + b << " " << w << "\n";

Result

3.14
    42|ab    |
30 abc

Exercise

Two decimals.

cout << fixed << (2) << x;

Quiz Test

Which reads a whole line?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.