| Text Mode | Binary Mode |
|---|---|
| ใน text mode มีการแปลงตัวอักษรต่างๆ เช่น "\r\n" ถูกแปลงเป็น "\n" | ใน binary mode ไม่มีการแปลงดังกล่าว |
| เขียนไฟล์: ofstream ofs("file.txt"); หรือ ofstream ofs; ofs.open("file.txt"); | เขียนไฟล์: ofstream ofs("file.txt", ios::binary); หรือ ofstream ofs; ofs.open("file.txt", ios::binary); |
| เพิ่มข้อความท้ายไฟล์: ofstream ofs("file.txt", ios::app); หรือ ofstream ofs; ofs.open("file.txt", ios::app); | เพิ่มข้อความท้ายไฟล์: ofstream ofs("file.txt", ios::app | ios::binary); หรือ ofstream ofs; ofs.open("file.txt", ios::app | ios::binary); |
| อ่านไฟล์: ifstream in("file.txt"); หรือ ifstream in; in.open("file.txt"); | อ่านไฟล์: ifstream in("file.txt", ios::binary); หรือ ifstream in; in.open("file.txt", ios::binary); |