นิยาม
std::cin เป็น object ของ class istream แทน standard input stream narrow characters (char) Corresponds to C stdin
คุณสมบัติ
- แหล่งข้อมูล: environment (keyboard, file)
- อ่านข้อมูล 2 แบบ: formatted (
>>) และ unformatted (read) - ประกาศใน
<iostream>external linkage, static duration
ตัวอย่าง: อ่าน int และพิมพ์
#include <iostream>
int main() {
int my_int;
std::cin >> my_int;
std::cout << my_int;
return 0;
}
Compile & Run
$ g++ hello.cpp $ ./a.out
ผลลัพธ์ (input: 15)
15
หมายเหตุ: เนื้อหานี้ทับซ้อนกับ ID 1004083497 และ 1004083505