CFile file("example.txt", CFile::modeRead); CString str; int length = (int)file.GetLength(); file.ReadString(str, length); file.Close();
CFile file("example.txt", CFile::modeRead); CString str; file.ReadString(str, 20); file.Close();In this example, the code reads the first 20 characters from the file "example.txt" and stores them in a CString object called str. The package library for CFile is the Microsoft Foundation Class (MFC) library.