다음을 통해 공유


CStdioFile::CStdioFile

The default version of the constructor works in conjunction with the CFile::Open member function to test errors.

CStdioFile( );
CStdioFile(
   FILE* pOpenStream 
);
CStdioFile(
   LPCTSTR lpszFileName,
   UINT nOpenFlags 
);

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 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

TCHAR* pFileName = _T("CStdio_File.dat");
CStdioFile f1;
if(!f1.Open(pFileName, CFile::modeCreate | CFile::modeWrite 
   | CFile::typeText)) 
{
   TRACE(_T("Unable to open file\n"));
}

CStdioFile f2(stdout);
try
{
   CStdioFile f3( pFileName,
      CFile::modeCreate | CFile::modeWrite | CFile::typeText );
}
catch(CFileException* pe)
{
   TRACE(_T("File could not be opened, cause = %d\n"),
      pe->m_cause);
   pe->Delete();
}

Requirements

Header: afx.h

See Also

Concepts

CStdioFile Class

CStdioFile Members

Hierarchy Chart