WeCodeAcademy

C++ User Input

std::cin reads typed input with >>. This example is shown with the input Ada then 36.

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

int main() {
  string name;
  int age;
  cout << "Name: ";
  cin >> name;
  cout << "Age: ";
  cin >> age;
  cout << name << " will be " << age + 1 << " next year" << endl;
  return 0;
}
Output
Name: Age: Ada will be 37 next year
Quick check

Which operator reads input from cin?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.