CStdioFile myFile; if (myFile.Open(_T("filename.txt"), CFile::modeRead)) { // file opened successfully, do something with it } else { // failed to open file }
CStdioFile myFile; if (myFile.Open(_T("filename.bin"), CFile::modeRead | CFile::typeBinary)) { // file opened successfully, do something with it } else { // failed to open file }This example is similar to the previous one, but specifies that the file is a binary file rather than a text file. This is done by passing the CFile::typeBinary flag to the mode parameter of the Open function. Package library: MFC (Microsoft Foundation Classes)