CFile file("example.txt", CFile::modeRead); char buffer[256]; while (file.Read(buffer, 256) > 0) { // do something with buffer } file.Close();
std::ifstream file("example.txt"); std::string line; while (std::getline(file, line)) { // do something with line } file.close();This code opens the file "example.txt" in input mode using std::ifstream, reads the file line by line using getline, performs some operation on each line, and then closes the file. The package library used in these examples is MFC (Microsoft Foundation Class Library), which provides file handling support for Windows applications.