Notes / C++ / Input & Output

Input & Output in C++ — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Input & Output C++ introduces stream-based I/O: cout for output and cin for input, both from <iostream>.

Syntax

syntax
cout << value;
cin >> variable;

Example

cpp
#include <iostream>
using namespace std;

int main() {
    int age;
    cout << "Enter your age: ";
    cin >> age;
    cout << "You are " << age << " years old." << endl;
    return 0;
}

Output

outputEnter your age: 20 You are 20 years old.

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Know when to use getline(cin, str) instead of cin >> str — for input that includes spaces.
Back to notes Read full lesson →