In actual work, we often need to operate text files in behavioral units, such as reading and writing
ini
Document, etc. If we use
C
or
C
The function in the runtime library is a little more troublesome. If you use
MFC
Use if you are doing
Cstdiofile
This class.
Let's take a look at CSTDIOFILE:
Class Cstdiofile: Public Cfile.
It is inherited from the CFILE class. In addition to constructor, it only provides two functions:
Virtual LPTSTR READSTRING (LPTSTSTSTSZZ, UINT NMAX); a line of reading text.
Virtual Bool ReadString (CString & Rstring); Write a line of text.
Cstdiofile hfile;
CfileException EX;
Bool ISEOF = FALSE;
IF (! hfile.open (m_hfilepath, cfile :: moderad | cfile :: sharedenywrite, & ex)) // Open file
{
Tchar Szerror [1024];
EX.GETERRORMESSAGE (Szerror, 1024);
AfxMessageBox (Szerror);
Return;
Else
{
While (! ISEOF)
{
ISEOF =! hfile.readstring (strtemp); // reads a line of text.
ISEOF BREAK;
...... DO Something
}
}
CString stratmp;
StrtMP = "Write a line of text / N";
Hfile.writeString (StrtMP);