CStdioFile( );
CStdioFile( FILE* pOpenStream );
CStdioFile( LPCTSTR lpszFileName, UINT nOpenFlags );
throw( CFileException );
Parameters
pOpenStream
Specifies the file pointer returned by a call to the C run-time function fopen.
lpszFileName
Specifies a string that is the path to the desired file. The path can be relative or absolute.
nOpenFlags
Sharing and access mode. Specifies the action to take when the file is opened. You can combine options by using the bitwise OR (|) operator. One access permission and a text-binary specifier are required; the create and noInherit modes are optional. See CFile::CFile for a list of mode options and other flags. In MFC version 3.0 and later, share flags are allowed.
Remarks
The default version of the constructor works in conjunction with the CFile::Open member function to test errors.
The one-parameter version constructs a CStdioFile object from a pointer to a file that is already open. Allowed pointer values include the predefined input/output file pointers stdin, stdout, or stderr.
The two-parameter version constructs a CStdioFile object and opens the corresponding operating-system file with the given path.
CFileException is thrown if the file cannot be opened or created.
Example
// example for CStdioFile::CStdioFile
char* pFileName = "test.dat";
CStdioFile f1;
if( !f1.Open( pFileName, CFile::modeCreate
| CFile::modeWrite | CFile::typeText ) ) {
#ifdef _DEBUG
afxDump << "Unable to open file" << "\n";
#endif
exit( 1 );
}
CStdioFile f2( stdout );
TRY
{
CStdioFile f3( pFileName,
CFile::modeCreate | CFile::modeWrite | CFile::typeText );
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not be opened "
<< e->m_cause << "\n";
#endif
}
END_CATCH