| Text mode | Binary mode |
|---|---|
| In text mode various character translations are performed i.e; “\r+\f” is converted into “\n” | In binary mode, such translations are not performed. |
| To write in the files: ofstream ofs (“file.txt”); Or ofstream ofs; ofs.open(“file.txt”); | to write in the files: ofstream ofs(“file.txt”,ios::binary); or ofstream ofs; ofs.open(“file.txt”, ios::binary); |
| To add text at the end of the file: Ofstream ofs(“file.txt”,ios::app); or ofstream ofs; ofs.open(“file.txt”, ios::app); | To add text at the end of the file: Ofstream ofs(“file.txt”,ios::app|ios::binary); or ofstream ofs; ofs.open(“file.txt”, ios::app|ios::binary); |
| To read files: ifstream in (“file.txt”); or ifstream in ; in.open(“file.txt”); | To read files: ifstream in (“file.txt”, ios::binary); or ifstream in ; in.open(“file.txt”, ios::binary); |