Summarize the online search content:
1. When a file is written in text mode, the newline (/N) is extended to/R/n. When the file is read, it is automatically converted back.
2. the binary method does not perform any expansion, which is consistent with the read/write content.
3. The default value is text.
Http://blog.csdn.net/wanfustudio/archive/2007/09/14/1785131.aspx
Appendix: two self-written functions for reading and writing files using fstream
# Include <fstream>
Using namespace STD;
Bool preprocess: readparsersltfile (tstring filename)
{
Tchar szfull [max_path] = {0 };
_ Tcscpy_s (szfull, max_path, m_szdatafiledir );
_ Tcscat (szfull, text ("//"));
_ Tcscat (szfull, filename. c_str ());
_ Tcscat (szfull, text ("_ r "));
Wifstream fin;
Fin. Open (szfull, IOS: Binary );
If (Fin. Bad ())
{
Return false;
}
Fin. imbue (STD: locale ("CHS "));
Tchar szsize [16] = {0 };
Fin. Getline (szsize, 16); // the size of the first behavior File
Int nsize = _ ttoi (szsize );
Tstring strtmp;
For (INT I = 0; I <nsize; I ++)
{
Getline (FIN, strtmp );
M_vsenparrslt.push_back (strtmp );
}
Fin. Close ();
Return true;
}
Void preprocess: writefiles (tstring filename, const vector <tstring> & vcontent)
{
Tchar szfull [max_path] = {0 };
_ Tcscpy_s (szfull, max_path, m_szdatafiledir );
_ Tcscat (szfull, text ("//"));
_ Tcscat (szfull, filename. c_str ());
Wofstream fout;
Fout. Open (szfull, IOS: Binary | ios_base: trunc );
// Fout. Clear ();
Fout. imbue (STD: locale ("CHS "));
Fout <vcontent. Size () <"/N ";
For (INT I = 0; I <vcontent. Size (); I ++)
{
Fout <vcontent [I]. c_str () <"/N ";
}
Fout. Close ();
}
The written content contains Chinese characters, so you must add: fout. imbue (STD: locale ("CHS "));
Tstring is a custom macro, representing string or wstring
# Ifdef _ Unicode
# Define tstring wstring
# Else
# Define tstring string
# Endif