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.

All topics in C++ Beginner

  1. Introduction to Programming & C++
  2. Your First C++ Program
  3. Variables & Data Types
  4. Input & Output
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Functions
  9. Vectors & Strings
  10. Classes & Objects
  11. Working with Classes
  12. Exception Handling
  13. Mini-Projects & Practice