← C++ Index

📺 <iostream> — Standard Input / Output Streams

The gateway to C++ I/O. Provides std::cin, std::cout, std::cerr, and std::clog. Use using namespace std; for study, or prefix with std:: in production code.

Include: #include <iostream> | Namespace: std | Compile: g++ -Wall -std=c++17 ...

📋 Classes, Functions & Symbols

NameType / SignatureDescription
std::coutstd::ostreamStandard output stream (to terminal)
std::cinstd::istreamStandard input stream (from keyboard)
std::cerrstd::ostreamStandard error stream (unbuffered)
std::clogstd::ostreamStandard log stream (buffered)
std::endlostream manipInsert newline and flush the stream
std::flushostream manipFlush the stream without a newline
std::wsistream manipSkip leading whitespace in input
operator<<ostream &Stream insertion operator (output)
operator>>istream &Stream extraction operator (input)
std::getlineistream &getline(istream &, string &, char delim='\n')Read full line into string

💡 Example Program

Copy, save as demo.cpp, and compile with the command at the bottom.

#include <iostream>
#include <string>
using namespace std;

int main() {
    cout << "Hello, C++ World!" << endl;
    cerr << "This goes to stderr" << endl;

    string name; int age;
    cout << "Enter your name: "; cin >> name;
    cout << "Enter your age:  "; cin >> age;
    cout << "Hello, " << name << "! Age: " << age << "\n";

    cin.ignore();
    string sentence;
    cout << "Enter a sentence: ";
    getline(cin, sentence);
    cout << "You typed: " << sentence << "\n";
    return 0;
}
// Compile: g++ -Wall -std=c++17 -o iostream_demo iostream_demo.cpp

🏠 Index  |  <string> →