CFile myFile("myfile.bin", CFile::modeRead); myFile.Seek(10, CFile::begin); // move to position 10 DWORD currentPosition = myFile.GetPosition(); // get current position int buffer[10]; myFile.Read(buffer, sizeof(buffer)); // read 10 integers from position 10
CFile myFile("myfile.bin", CFile::modeCreate | CFile::modeWrite); char buffer[] = "hello world"; myFile.Write(buffer, sizeof(buffer)); // write "hello world" to file DWORD currentPosition = myFile.GetPosition(); // get current position (end of file)In this example, a file named "myfile.bin" is created for writing. The string "hello world" is written to the file using CFile::Write(). The current position is then obtained using CFile::GetPosition(), which should be at the end of the file. Package library: MFC (Microsoft Foundation Class Library)