void EditView::ReadTitle(CString strName)
{
CString content="";
CStdioFile file;
CString fileName = strName;
if (file.Open(fileName, CFile::modeRead | CFile::typeText))
{
file.SeekToBegin();
CString str;
int len = 512 - 2;
file.ReadString(str); // A null character ('\0') is appended.
if ("" != str)
content += str;
file.Close();
}
else
AfxMessageBox("读取失败!");
this->SetWindowText(content);
}
strName是路径,调试是正确的,而且file.Open()也成功了。
就是读取内容ReadString(str)时,str显示字符串中的字符无效。
不知是哪里的问题。。
这里问题已经找到了。这里是
content += str;
时OnEnChange()函数被调用了,里面有writein函数
str显示字符串中的字符无效
具体的错误是什么?没有正确设置\0,还是有乱码?
比如我文本中是ssss,读取了显示就一个是字,类似乱码那种
你这个len变量是干啥的,没见你有用到啊