<iostream> provides std::cin, std::cout, std::cerr, std::clog for standard I/O. It's the C++ way to read from stdin and write to stdout/stderr.
Use std::cout for normal output, std::cerr for errors, and std::cin for input. For formatted output, prefer std::format in C++20, but iostream is portable and widely used.
This example reads a line from standard input and echoes it back, demonstrating basic stream input/output.
// compile: g++ -std=c++11 -o iostreamexample iostreamexample.cpp // run: ./iostreamexample // description: reading and printing with iostream #include <iostream> #include <string> int main() { std::cout << "enter your name: "; std::string name; std::getline(std::cin, name); std::cout << "hello, " << name << "!\n"; return 0; }