Ch 4 · Input & Output · C++
Topic 4 of 13 in C++ — Complete Tutorial (Beginner) — 2 lessons.
Reading Input with cin
While cout prints output, cin ("see-in") reads input the user types, using the >> operator. The value is stored directly in the variable you name — no & needed (unlike C's scanf). You can read several values in a row. cin >> stops reading at whitespace, so for a full line of text including spaces, use getline.
Formatting Output
C++ can format numbers using tools from <iomanip>. setprecision with fixed controls decimal places, and setw sets a minimum field width for lining up columns. These manipulators are inserted into the cout stream just like values, affecting the output that follows.