I have declared a char* strLine, then I allocated mem to be used to read a text file one line at a time as below:
char* strLine = (char*) malloc(sizeof(char) * 2048);
fp = fopen(myFilePath, "rt");
//code to read in a line one character at a time till it reach '\n'
//then strLine[lastIndex] = '\0'
//below is where problem happens
the CString is a MFC CString and it always fail with the following message:
CMemoryException at memory location 0x0021ebe0
If I use a fixed length char array, such as char strLine, then CString str(strLine) doesn't have any problem. So it seem to me, MFC CString constructor wants a const char array with a fixed length, but I also read somewhere that MFC CString constructor can also take a null-terminated char array (char *), so could someone help explain why I can't use the dynamically allocated char array to instantiate a MFC CString?
The program uses MFC in a shared dll, not using ATL, uses Multi-Byte Character Set.