This is probably a very strange question, even when I post on 9cbs.net, someone answers like this "because if you call CtextFile, you must ask why cstractfile is not CSTDIOFILE?". It is also more serious that the CSTDiofile class can operate both text files can also operate the binary files. He has Write (), read () and other methods, not WriteString (), readstring (). Can't CTEXTFILE, see the name of the name is to access the file file ". Indeed, the class name of the class library is carefully confirmed to ensure the ability to correctly describe the functions, but as a inheritance class is to indicate that the newly added function (the function of the base class is definitely to inherit), so above The statement has not been awkward. To say why, first we have to see what is TextFile. We all know that there are 2 modes, typebinary and typetext in the CFILE class. If you are a ctextfile class, you must, you have to force the Typetext type. So what is CSTDIOFILE did?
Bool cstdiofile :: Open (LPCTSTR LPSZFILENAME, UINT NOPENFLAGS, CFILEXCEPTION * PEXCEPTION)
{
...
/// Call the base class to open the file, pay attention to filter the text attribute of the file through NopenFlags & ~ Typetext
IF (! cfile :: Open (lpszfilename, (Nopenflags & ~ Typetext), PEXCEPTION)
Return False;
...
/// Conversion Open mode
IF (Nopenflags & Typebinary)
Szmode [NMODE ] = 'b', nflags ^ = _o_text;
Else
Szmode [NMODE ] = 'T';
...
// Open A C-Runtime Low-Level File Handle
INT nhandle = _open_OSfhandle ((uint_ptr) m_hfile, nflags);
// Open a c-runtime stream from That Handle
IF (nhandle! = -1)
m_pstream = _fdopen (nhandle, szmode);
...
} It can be seen from the above code that cstdiofile enforces the TypeText flag so that the file open mode can be binary mode. This already proves that cstdiofile is not a pure TEXTFILE class. Look carefully, look at the code, after calling the base class, use _Open_OSFHANDLE and _FDOpen to make strange conversions, check the type of m_pstream
File * m_pstream; // stdio file
This is a File structure of standard I / O. If further research Cstdiofile's source code, it will also find that it is a function of calling standard I / O, such as using _fputts / _fgetts to implement WritestRing / ReadString, with FREAD / FWRITE / FSEEK to replace Read / Write / SEEK. Note that cstdiofile does not use the CFile's READ / WRITE / SEK function. If you will open it directly in Open, cstdiofile can even say that there is no relationship with cfile. This class is called CSTDIOFILE.