CFile file; if (!file.Open(_T("example.txt"), CFile::modeRead | CFile::typeText)) { // Handle error }
CFile file; if (!file.Open(_T("example.bin"), CFile::modeWrite | CFile::typeBinary)) { // Handle error }In this example, we create a CFile object and try to open a binary file named "example.bin" in write mode using the bitwise OR operator with CFile::modeWrite and CFile::typeBinary. If the file cannot be opened, an error is handled. Package library: MFC (Microsoft Foundation Classes)