Reading a file...
Posted on 2004-04-05
Using MFC VC++6, I created a file which has the character 'a' at position 1. I want to read the file and convert it to a CString and then display it to a message box.
Here is the code I have been working with.
const int MAX_STRING_LENGTH = 10;
MyFile.Open("...MyfilePath", CFile::modeNoTruncate | CFile::modeRead );
char* TempBuf = MyString.GetBuffer(MAX_STRING_LENGTH);
UINT NumChars = MyFile.Read((void FAR*) TempBuf, MAX_STRING_LENGTH - 1);
I get a run time exception error when I run this code.
Is there an easier way to do this?