如何在 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.