0Pricing
C++ Academy · Lesson

Using std::cin and std::cout Properly

Stream input and output with the standard streams and avoid common pitfalls.

The iostream Header

Both std::cin and std::cout are objects from the <iostream> header. They model the standard input and output streams of your terminal.

Output with std::cout

Stream values to std::cout with <<. It works for any type that has an operator<< overload — including all built-in types and std::string.

int age = 30;
std::string name = "Ada";
std::cout << "Name: " << name << ", Age: " << age << "\n";

All lessons in this course

  1. Using std::cin and std::cout Properly
  2. Formatting Output with iomanip
  3. Reading Input Safely with getline
  4. Working with std::cerr and std::clog
← Back to C++ Academy