Advertisement
Beginner C++, I/O Streams

What are C++ I/O streams?

Short answer

C++ streams are a type-safe, extensible I/O abstraction in : std::cin (input), std::cout (output), std::cerr (unbuffered error), and std::clog (buffered log). They use operator > (extraction), which are overloadable for user types, unlike C's printf/scanf format strings.

Save C++ mock interview
Advertisement
AModel answer
C++ streams are a type-safe, extensible I/O abstraction in <iostream>: std::cin (input), std::cout (output), std::cerr (unbuffered error), and std::clog (buffered log). They use operator<< (insertion) and operator>> (extraction), which are overloadable for user types, unlike C's printf/scanf format strings.
std::cout << "value: " << 42 << "\n";
int x; std::cin >> x;
Real-world example
A program reads user input with std::cin and prints results with std::cout using overloaded operators.
Likely follow-ups
  • What are cin, cout, cerr, clog? | Why are streams type-safe?
Related topics