用二進位制和文字模式編寫的 C++ 檔案之間的區別


文字模式二進位制模式
在文字模式中執行各種字元
 轉換,即:
“\r+\f”轉換為“\n”
在二進位制模式下,不執行此類轉換
要寫入檔案
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);

更新於: 30-Jul-2019

544 次觀看

啟動您的職業

透過完成課程獲得認證

開始吧
廣告