Brief introduction:
CStdioFile
CObject |
└cfile |
└cstdiofile |
text provides special handling of hard carriage return-line break pairs :
When you write a newline character (0x0A) to a text-like CStdioFile object, the byte pair (0x0a,0x0d) is sent to the file, which automatically expands "\ n" to "\ r \ n", which is considered by the individual to be compatible with Windows, but has advantages and disadvantages;
When you read a file, the byte pair (0x0a,0x0d) is translated into a byte (0x0A).
CStdioFile Class Members
Data members
M_pstream |
Contains a pointer to an open file |
Structure
CStdioFile |
Constructs a CStdioFile object from a path or file pointer |
Text Read/write
ReadString |
Reading a line of text |
WriteString |
Write a line of text |
function Prototypes:
Virtual LPTSTR ReadString (LPTSTR lpsz, UINT nMax);
BOOL ReadString(cstring& rString);
virtual void writestring(LPCTSTR lpsz);
Precautions :
Read write files, sometimes for the sake of convenience, like to use ReadString () and WriteString (), because after all, this can be read and write, do not care about the row to differentiate.
But ReadString () and WriteString () to "\ n" Compatibility has broken my big event, for example:
Open file
cstdiofile F;
CFileException e;
if (!f.open ("D:\\test.txt", Cfile::modecreate | Cfile::modenotruncate | Cfile::modereadwrite | Cfile::sharedenynone, &e)) ""
{
return FALSE;
}
F.writestring ("E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\fiddler.exe\r\n");
F.writestring ("E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\execaction.exe\r\n");
F.writestring ("E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\fiddler.exe.config\r\n");
F.writestring ("E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\fiddlerhook\chrome.manifest\r\n");
F.writestring ("E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\fiddlerhook\content\about.xul\r\n");
F.close ();
Read File
f.open (M_supgradefile, cfile::moderead);
CString sFile = "";
Vector<cstring> Vecfile;
while (M_hupgradefile.readstring (sFile))
{
vecfile.push_back (sFile);
}
The results are as follows:
E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\fiddler.exe\r
E:\jiangqin\GameLinker\GameLinker\ version fallback \ fiddler\execaction.exe\r
E:\jiangqin\GameLinker\GameLinker\ version fallback \fiddler\fiddler.exe.config\r
e:\ Jiangqin\gamelinker\gamelinker\ version fallback \fiddler\fiddlerhook\chrome.manifest\r
E:\jiangqin\GameLinker\ Gamelinker\ version Fallback \fiddler\fiddlerhook\content\about.xul\r
The result is a "\ r" at the end of each file name, which is not what I expected. Why is that so? The reasons are as follows:
Because WriteString () writes the file, it automatically expands "\ n" to "\ r \ n" so that the "\ r \ n" We add becomes "\r\r\n", </span></span
Therefore, when writing a file, the end of the string only needs to add "\ n", so that the end of the data read by the row will not contain "\ r".