ความแตกต่างหลัก
- cin: object ของ input stream ใช้รับ input จากไฟล์ console เป็นต้น
- cout: object ของ output stream ใช้แสดงผล output
cin เป็น input statement, cout เป็น output statement
ออเปอเรเตอร์ที่ใช้
cinใช้ extraction operator>>coutใช้ insertion operator<<
ตัวอย่าง: รับค่าและแสดงผล
#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