用二進位制和文字模式編寫的 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); |
廣告