在这里,我们将看到如何从用户读取整数并以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