Utilizor
Contact Us

C++ User Input

Getting user input with cin.

C++ User Input

You have already learned that cout is used to output (print) values. Now we will use cin to get user input.

cin is a predefined variable that reads data from the keyboard with the extraction operator (>>).

In simple terms, cout takes data from the program and sends it to the screen, while cin takes data from the keyboard and sends it to the program.

Inputting Strings

Consider using the getline() function to read a line of text. It takes cin as the first parameter, and the string variable as the second.