Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

วิธีอ่านและพิมพ์ค่าจำนวนเต็มใน 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