Difference between files written in binary and text mode in C++

C++Server Side ProgrammingProgramming

Text modeBinary 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);
raja
Published on 18-Jun-2019 08:22:34
Advertisements