ความแตกต่างหลัก
ทั้ง cerr และ clog เป็น object ของ stderr stream แต่ทำงานต่างกัน:
1. cerr - Un-buffered Standard Error Stream
- Instance ของ ostream class
- ใช้แสดง error message ทันที
- Un-buffered: ไม่มี buffer เก็บข้อความ ส่งออกทันที
- เหมาะสำหรับ critical errors ที่ต้องแสดงทันที
2. clog - Buffered Standard Error Stream
- Instance ของ ostream class
- ใช้แสดง error แต่ buffered
- ข้อความถูกเก็บใน buffer จนกว่าจะเต็มหรือ flush
- เหมาะสำหรับ logging ที่ไม่เร่งด่วน
3. cout - Standard Output Stream (เปรียบเทียบ)
- Instance ของ ostream class
- ใช้ผลลัพธ์โปรแกรมปกติ ไปยัง display screen
- ใช้ insertion operator
<<
สรุป
| Stream | Buffer | วัตถุประสงค์ |
|---|---|---|
| cout | Buffered | Normal program output |
| cerr | Un-buffered | Immediate error messages |
| clog | Buffered | Logging/non-critical errors |