Print Number Entered by User in C++

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.

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

C++ Program

#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.