0
0
C++programming~5 mins

Using cin for input in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is cin used for in C++?

cin is used to get input from the user through the keyboard.

Click to reveal answer
beginner
How do you read an integer value from the user using cin?

Use cin >> variableName; where variableName is an integer variable.

Click to reveal answer
intermediate
What happens if the user enters a non-integer value when reading an integer with cin?

cin will fail to read the input and set an error state. The variable will not change.

Click to reveal answer
beginner
How can you read multiple values in one line using cin?

You can chain extractions like cin >> var1 >> var2 >> var3; to read multiple inputs separated by spaces.

Click to reveal answer
beginner
What header file must be included to use cin?

You must include <iostream> to use cin in your program.

Click to reveal answer
Which header file is required to use cin in C++?
A<cstdio>
B<cmath>
C<string>
D<iostream>
What does the operator >> do when used with cin?
ACompares two values
BOutputs data to the screen
CExtracts input from the user
DAssigns a value to a variable
How do you read two integers from the user in one line?
Acin >> a >> b;
Bcin << a << b;
Ccin >> a, b;
Dcin << a, b;
What happens if the user enters a letter when cin expects an integer?
Acin crashes the program
Bcin fails and sets an error state
Ccin ignores the input and waits
Dcin converts the letter to zero
Which of these is the correct way to declare a variable and read input into it?
Aint age; cin >> age;
Bcin >> int age;
Cint age = cin >>;
Dcin age >> int;
Explain how to use cin to get input from a user in a C++ program.
Think about the steps from including the right file to reading the value.
You got /4 concepts.
    Describe what happens internally when you use cin >> variable; and the user types input.
    Imagine how the program listens and processes what you type.
    You got /5 concepts.