In this C++ tutorial, you will learn how to write a program to read a number entered by user, and print it to standard output.

C++ Print number entered by user

To print a number entered by user in C++, read the number from user using cin, store this number in a variable, and then print this number to output using cout.

Program

In the following program, we read a number to n from user via console input, and print this number to console output.

C++ Program

</>
Copy
#include <iostream>
using namespace std;

int main() {
    int n;
    cout << "Enter a number : ";
    cin >> n;
    
    cout << "You entered : " << n << endl;
}

Output

Enter a number : 5421
You entered : 5421
Program ended with exit code: 0
Enter a number : 4444
You entered : 4444
Program ended with exit code: 0

Conclusion

In this C++ Tutorial, we learned how to print a number entered by user in C++, with example program.