Tutorials

C++ Tutorial

All Tutorials Learning Tools Login

C++ Tutorial · Chapter 6 of 13

C++ Input

Read values with cin.

cin >> variable reads input. Prompt the user first with cout.

For full lines with spaces, getline is better later; beginners often start with cin >>.

cin sample Try it Yourself »
#include <iostream>
using namespace std;

int main() {
    string name;
    int age;
    cout << "Enter your name: ";
    cin >> name;
    cout << "Enter your age: ";
    cin >> age;
    cout << "Hello " << name << ", you are " << age << " years old." << endl;
    return 0;
}

Classroom Tips

  • Provide Console Input in CoderKiosk before interactive runs.