1、 启动Visual C++6.0,生成一个单文档的工程,将该工程命名为ReadCoodinate。2、 添加一个“读取文本数据”的菜单项。3、 给视图类添加两个public变量:CArray<CPoint,CPoint> m_PointArray; // 用于记录坐标点数据int m_PointNum; // 用于记录坐标点个数,在视图类构造函数中初始化为0。4、 给“读取文本数据”添加相应的单击消息响应函数。代码如下:void CReadCoodinateView::OnReaddata() { // TODO: Add your command handler code here CFileDialog dlg(TRUE); // 定义一个文件对话框变量 if(dlg.DoModal()==IDOK) { CString m_FilePath = dlg.GetPathName(); //取得文件路径及文件名 CStdioFile File; File.Open(m_FilePath,CFile::modeRead); //以读模式打开文本文件 CString FileData; //定义一个CString变量作为缓冲区 File.ReadString(FileData);//读取第一行数据,第一行数据为坐标点数据 /*定义两个临时字符串,并初始化为'\0'*/ char TempStr1[10]; char TempStr2[10]; memset(TempStr1,'\0',10); memset(TempStr2,'\0',10); sscanf(FileData,"%s",TempStr1); m_PointNum = atoi(TempStr1); // 获取坐标点个数 /*逐行读取坐标数据*/ for (int i = 0;i<m_PointNum;i++) { File.ReadString(FileData); sscanf(FileData,"%s %s",TempStr1,TempStr2); m_PointArray.Add(CPoint(atoi(TempStr1),atoi(TempStr2)));//将其存入坐标点数组 } CDC *pDC = GetDC(); //获取设备环境; /*根据坐标点绘出直线*/ for (i = 0;i<m_PointNum-1;i++) { pDC->MoveTo(m_PointArray[i].x,m_PointArray[i].y); pDC->LineTo(m_PointArray[i+1].x,m_PointArray[i+1].y); } ReleaseDC(pDC); //使用完后,释放设备环境 }}这个的编译不能通过。我加了个#include <afxtempl.h> ,还是不行。该怎么修改啊。多谢了
d:\程序\vc++自己编程\文件\readcoodinate2\readcoodinate2view.h(41) : error C2501: 'CArray' : missing storage-class or type specifiers
d:\程序\vc++自己编程\文件\readcoodinate2\readcoodinate2view.h(41) : error C2501: 'm_PointArray' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(151) : error C2065: 'm_PointArray' : undeclared identifier
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(151) : error C2228: left of '.Add' must have class/struct/union type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(167) : error C2109: subscript requires array or pointer type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(167) : error C2228: left of '.x' must have class/struct/union type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(167) : error C2109: subscript requires array or pointer type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(167) : error C2228: left of '.y' must have class/struct/union type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(169) : error C2109: subscript requires array or pointer type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(169) : error C2228: left of '.x' must have class/struct/union type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(169) : error C2109: subscript requires array or pointer type
D:\程序\VC++自己编程\文件\ReadCoodinate2\MainFrm.cpp(169) : error C2228: left of '.y' must have class/struct/union type
ReadCoodinate2.cpp
d:\程序\vc++自己编程\文件\readcoodinate2\readcoodinate2view.h(41) : error C2146: syntax error : missing ';' before identifier 'm_PointArray'
d:\程序\vc++自己编程\文件\readcoodinate2\readcoodinate2view.h(41) : error C2501: 'CArray' : missing storage-class or type specifiers
d:\程序\vc++自己编程\文件\readcoodinate2\readcoodinate2view.h(41) : error C2501: 'm_PointArray' : missing storage-class or type specifiers
ReadCoodinate2View.cpp
错误没贴完。重新上
如果是StdAfx.h 需要rebuild all你响应的是view中的消息还是mainfrm中的消息?
请确认一下
error C2146: syntax error : missing ';' before identifier 'm_PointArray'
error C2501: 'CArray' : missing storage-class or type specifiers
error C2501: 'm_PointArray' : missing storage-class or type specifiers
error C2955: 'CArray' : use of class template requires template argument list
fatal error C1903: unable to recover from previous error(s); stopping compilation
Generating Code...