注册 登录
编程论坛 VC++/MFC

编译以下程序为什么总提示错误(提示见最后一行红字)?

kxfei5555w 发布于 2010-10-03 15:09, 714 次点击
int CMainFrame::ReadDataFromFile(void)
{
    CFile file(_T("\\VC教程\\SIO.txt"),CFile::modeRead);
    char cBuf[1024];
    memset(cBuf,0,1024);
    file.Read(cBuf,1024);
    m_gstrReadText=cBuf;
    m_gstrReadText="读取数据:"+m_gstrReadText;
    file.Close();
    Invalidate();
}
1>e:\mfcopttext\mfcopttext\mainfrm.cpp(112) : error C2065: 'm_gstrReadText' : undeclared identifier
6 回复
#2
ljt2010-10-03 16:34
你这不没定义么,你就直接给用了,m_gstrReadText的类型呢
#3
cnfarer2010-10-03 20:30
加一句:char * m_gstrReadText;
这一句:m_gstrReadText="读取数据:"+m_gstrReadText; 也是有问题的!
#4
kxfei5555w2010-10-04 20:04
回复 3楼 cnfarer
我照你说的改了之后,的确是m_gstrReadText="读取数据:" + m_gstrReadText;有问题,编译后提示1>e:\新建文件夹\lpjj\lpjj\lpjjdlg.cpp(164) : error C2440: '=' : cannot convert from 'const wchar_t [6]' to 'char',这是为什么?
#5
红色警戒2010-10-04 20:11
把gstrReadText改为CString类型
 
    CSting m_gstrReadText;
    CFile file(_T("\\VC教程\\SIO.txt"),CFile::modeRead);
    char cBuf[1024];
    memset(cBuf,0,1024);
    file.Read(cBuf,1024);
    m_gstrReadText.Format("%s", cBuf);
    m_gstrReadText="读取数据:"+m_gstrReadText;
    file.Close();
    Invalidate();
#6
kxfei5555w2010-10-05 09:29
回复 5楼 红色警戒
运行后出现以下四处错误:
1>e:\新建文件夹\lpjj\lpjj\lpjjdlg.cpp(160) : error C2065: 'CSting' : undeclared identifier
1>e:\新建文件夹\lpjj\lpjj\lpjjdlg.cpp(160) : error C2146: syntax error : missing ';' before identifier 'm_gstrReadText'
1>e:\新建文件夹\lpjj\lpjj\lpjjdlg.cpp(160) : error C2065: 'm_gstrReadText' : undeclared identifier
1>e:\新建文件夹\lpjj\lpjj\lpjjdlg.cpp(165) : error C2228: left of '.Format' must have class/str
#7
ybjx19872010-10-05 17:37
CString 不是CSting
1