🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C++ Notes
Topic #15

C++ User Input


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 the following example, the user can input a number, which is stored in the variable x. Then we print the value of x:

Example

int x;
cout << "Type a number: "; // Type a number and
press enter
cin >> x; // Get user
input from the keyboard
cout << "Your number is: " << x;
// Display the input value

Note: Good To Know cout is pronounced "see-out". Used for output, and uses the insertion operator (<<) cin is pronounced "see-in". Used for input, and uses the extraction operator (>>)


Creating a Simple Calculator

In this example, the user must input two numbers. Then we print the sum by calculating (adding) the two numbers:

Example

  int x, y;
int sum;
cout << "Type a number: ";
cin >> x;
cout << "Type another number: ";
cin >>
  y;
sum = x + y;
cout << "Sum is: " << sum;

There you go! You just built a basic calculator!


Complete Reference

Tip: Both cin and cout belongs to the <iostream> library, which is short for standard input / output streams. For a complete reference of objects along with detailed information, go to our C++ iostream Reference.

Want to go beyond the notes?

Join CodingNow 2.0's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

C++ User Input – FAQs

Quick answers about learning C++ User Input in C++.

This free note from CodingNow 2.0 explains C++ User Input in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, including C++ User Input, is 100% free with no signup required.
With focused practice, most students grasp C++ User Input in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now