首页上一页 1 下一页尾页 4 条记录 1/1页
书中例题运行错误
发表在C语言图书答疑
2016-03-22
是否精华
是
否
版块置顶:
是
否
《从入门到精通》第六章 6.7.1 通用对话框中例题6.6 ,创建了打开、保存按钮后,输入相关代码,比如打开按钮的的代码:
void CFileDialogDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"All Files(*.TXT)|*.TXT||",AfxGetMainWnd());
CString strPath,strText="";
if(dlg.DoModal() == IDOK)
{
strPath = dlg.GetPathName();
m_OpenPath.SetWindowText(strPath);
CFile file(strPath,CFile::modeRead);
char read[10000];
file.Read(read,10000);
for(int i=0;i<file.GetLength();i++)
{
strText += read[i];
}
file.Close();
m_FileText.SetWindowText(strText);
}
}
运行编译后提示错误:
Configuration: FileDialog - Win32 Debug--------------------
Compiling...
FileDialogDlg.cpp
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(183) : error C2065: 'm_OpenPath' : undeclared identifier
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(183) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(187) : warning C4018: '<' : signed/unsigned mismatch
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(192) : error C2065: 'm_FileText' : undeclared identifier
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(192) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(208) : error C2065: 'm_SavePath' : undeclared identifier
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(208) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(210) : error C2228: left of '.GetWindowTextA' must have class/struct/union type
执行 cl.exe 时出错.
FileDialogDlg.obj - 1 error(s), 0 warning(s)
不知道是哪里出错了?请问版主,谢谢!
void CFileDialogDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"All Files(*.TXT)|*.TXT||",AfxGetMainWnd());
CString strPath,strText="";
if(dlg.DoModal() == IDOK)
{
strPath = dlg.GetPathName();
m_OpenPath.SetWindowText(strPath);
CFile file(strPath,CFile::modeRead);
char read[10000];
file.Read(read,10000);
for(int i=0;i<file.GetLength();i++)
{
strText += read[i];
}
file.Close();
m_FileText.SetWindowText(strText);
}
}
运行编译后提示错误:
Configuration: FileDialog - Win32 Debug--------------------
Compiling...
FileDialogDlg.cpp
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(183) : error C2065: 'm_OpenPath' : undeclared identifier
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(183) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(187) : warning C4018: '<' : signed/unsigned mismatch
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(192) : error C2065: 'm_FileText' : undeclared identifier
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(192) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(208) : error C2065: 'm_SavePath' : undeclared identifier
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(208) : error C2228: left of '.SetWindowTextA' must have class/struct/union type
D:\C语言学习\C++例题程序\FileDialog\FileDialogDlg.cpp(210) : error C2228: left of '.GetWindowTextA' must have class/struct/union type
执行 cl.exe 时出错.
FileDialogDlg.obj - 1 error(s), 0 warning(s)
不知道是哪里出错了?请问版主,谢谢!