如何在 C++ 中读取和打印整数


现在我们可以看到如何从用户读取整数并将其显示为 C++。我们将使用 cin 运算符来输入,使用 cout 运算符来显示。语法如下所示 -

输入 -

int x;
cin >> x;

输出 -

int x = 110;
cout << x;

示例

 实时演示

#include<iostream>
using namespace std;
int main(int argc, char const *argv[]) {
   int x;
   int y = 50;
   cout << "Enter some value: ";
   cin >> x;
   cout << "The given value is: " << x << endl;
   cout << "The value of y is: " << y;
}

输出

Enter some value: 100
The given value is: 100
The value of y is: 50

更新日期:2020 年 1 月 3 日

474 次浏览

启动你的 职业生涯

参加课程并获得认证

开始
广告
© . All rights reserved.