Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 752 Bytes

File metadata and controls

36 lines (24 loc) · 752 Bytes

C++ 程序:打印用户输入的数字

原文: https://www.programiz.com/cpp-programming/examples/read-print-integer

在此示例中,您将学习打印用户使用 C++ cout语句输入的数字。

示例:打印用户输入的数字

#include <iostream>
using namespace std;

int main()
{    
    int number;

    cout << "Enter an integer: ";
    cin >> number;

    cout << "You entered " << number;    
    return 0;
}

输出

Enter an integer: 23
You entered 23

该程序要求用户输入一个数字。

当用户输入整数时,使用cin将其存储在变量num中。

然后使用cout将其显示在屏幕上。