All lessons

2. Variables and types

Input and output

0 of 4 activities0%

Reading 1

Streams go both ways

Open

cout (console output) prints. cin (console input) reads.

The operator << sends data toward cout. The operator >> pulls data from cin into a variable.

When a lesson or assignment provides input, that text is fed to cin as if the user typed it.

int n;
cin >> n;
cout << "You entered " << n << endl;

Check 2

Reading input

Open

Which operator is used with cin to read a value into a variable?

Try it 3

Echo a number

Open

This playground already has sample input 7. Run it, then change the input box and run again.

main.cpp
Loading editor…
Output will appear here.

Assignment 4

Add two integers

Open

Read two integers from input and print their sum, followed by a newline.

main.cpp
Loading editor…