首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

VC读文本画等高线的异常

2012-02-05 
VC读文本画等高线的错误我用VC读一个文本文件,是关于一些等高线的坐标,但是写成后,却出现如下错误:弹出一

VC读文本画等高线的错误
我用VC读一个文本文件,是关于一些等高线的坐标,但是写成后,却出现如下错误:

    弹出一个对话框,写的是:
Unhandled   excettion   in   Contour.exe(MSVCRTD.DLL);0xC0000005:Access   Violation

这是什么错误啊?
读文件的程序如下:

void   CContourView::OnPaint()  
{
CDC   *pDC;
pDC=GetDC();
//   TODO:   Add   your   command   handler   code   here
CFile   file;
ASSERT(file.Open( "contourlines.txt ",CFile::modeRead));
CArchive   arf(&file,CArchive::load);
CString   strTemp;
        char   sep[]= ", ";
char   *token;
count=0;

        arf.ReadString(strTemp);

if(strTemp== "BEGIN ")
{
arf.ReadString(strTemp);
//int   start;
start=int(atof(strTemp));
arf.ReadString(strTemp);
char   *p=new   char[strTemp.GetLength()+1];
strcpy(p,strTemp);
token=strtok(p,sep);
xmin=atof(token);
token=strtok(NULL,sep);
xmax=atof(token);
token=strtok(NULL,sep);
ymin=atof(token);
token=strtok(NULL,sep);
ymax=atof(token);

arf.ReadString(strTemp);
while(strTemp!= "END ")
{
contourlines[count].code=int(atof(strTemp));
arf.ReadString(strTemp);
contourlines[count].high=atof(strTemp);
arf.ReadString(strTemp);
int   num=contourlines[count].number=int(atof(strTemp));
arf.ReadString(strTemp);
contourlines[count].point=new   Point[num];
for(int   i=0;i <contourlines[count].number;i++)
{
arf.ReadString(strTemp);
p=new   char[strTemp.GetLength()+1];
strcpy(p,strTemp);
token=strtok(p,sep);
contourlines[count].point[i].x=atof(token);
token=strtok(NULL,sep);
contourlines[count].point[i].y=atof(token);
arf.ReadString(strTemp);
}
                     
count++;
}
}
arf.Close();
file.Close();


OnInitialize();

}

void   CContourView::OnInitialize()
{
        findheight=0;
        dheight=5;
RedrawWindow();
findheight=0;
double   dy=(ymax+ymin)/2;
double   dx=(xmax+xmin)/2;
for(int   k=0;k <count;k++)
{
display[k].code=contourlines[k].code;
display[k].high=contourlines[k].high;
display[k].number=contourlines[k].number;
display[k].point=new   Point[contourlines[k].number];
for(int   l=0;l <contourlines[k].number;l++)
{
display[k].point[l].y=860(contourlines[k].point[l].x-dx)/5
display[k].point[l].x=(contourlines[k].point[l].y-dy)/5+670                  

}
}
drawContourLine();
}

void   CContourView::drawContourLine()
{
        CPen   *mypen=new   CPen(0,2,RGB(0,0,0));
CPen   *mypen1=new   CPen(0,1,RGB(0,0,0));
CPen   *mypen2=new   CPen(0,1,RGB(225,0,0));
CPen   *mypen3=new   CPen(0,2,RGB(225,0,0));
CPen   *oldpen;
CClientDC   dc(this);

for(int   k=0;k <count;k++)
{
if(int(display[k].high)%dheight==0)
{
if(int(display[k].high)%(5*dheight)==0&&display[k].high!=findheight)
oldpen=dc.SelectObject(mypen);
else   if(int(display[k].high)%(dheight*5)!=0&&display[k].high==findheight)


oldpen=dc.SelectObject(mypen2);
else   if(int(display[k].high)%(dheight*5)==0&&display[k].high==findheight)
oldpen=dc.SelectObject(mypen3);
dc.MoveTo(int(display[k].point[0].x),int(display[k].point[0].y));
for(int   l=0;l <contourlines[k].number;l++)
{
dc.LineTo(int(display[k].point[l].x),int(display[k].point[l].y));
}
oldpen=dc.SelectObject(mypen1);
}
}
dc.SelectObject(oldpen);
ReleaseDC(&dc);
}


其中contourlines.txt中的部分代码如下:BEGIN
10000
91400.000000,104600.000000,51800.000000,56200.000000
71011
110.000000
4
101368.400000,54000.000000
101359.200000,53999.200000
101352.400000,53999.300000
101347.400000,54000.000000
71011
85.000000
3
99892.400000,54000.000000
99894.900000,53997.900000
99895.400000,54000.000000
71011
85.000000
5
99638.200000,54000.000000
99640.200000,53997.800000
99643.900000,53996.100000
99648.500000,53996.500000
99652.700000,54000.000000
71012
125.000000
9
100091.600000,54000.000000
100083.300000,53997.300000
100076.200000,53995.600000
100069.700000,53994.700000
100063.700000,53994.600000
100057.700000,53995.100000
100052.100000,53996.200000
100047.200000,53997.800000
100043.300000,54000.000000
71011


[解决办法]
跟踪到你的构造函数里看看。
CContourLine::CContourLine(int c,double h,int n,point *p)
里的c, h, n, p传进相应的值了吗?

热点排行