CFile file; // open file named "example.txt" for reading and writing if (file.Open(_T("example.txt"), CFile::modeReadWrite)) { // file opened successfully, manipulate file here file.Close(); // close the file when done } else { // handle error in opening file }
CFile file; // open file named "example.txt" for reading only if (file.Open(_T("example.txt"), CFile::modeRead)) { // file opened successfully, manipulate file here file.Close(); // close the file when done } else { // handle error in opening file }The package library for CFile Open is the Microsoft Foundation Class (MFC) library for C++.