文件内容如下:已经缩减了
minX 82.290100
maxX 86.682739
minY 36.588001
maxY 39.070396BEGIN
1
85.8959579 38.7232475
85.9086761 38.7299919
END
12
84.0129242 37.8440437
84.0286560 37.8365784
END
14
84.0880280 37.8387718
84.1121826 37.8357544
END
18
86.1660233 37.3344154
86.4753265 37.3189392
END
21
84.5136642 37.3348999
84.2972336 37.1641731
END
23
85.0533371 37.1870651
85.1399384 37.0708580
85.2159576 36.9937019
85.2421417 36.9288216
END
24
86.4000778 37.1655426
86.2833939 37.0844727
86.2305145 37.1057358
86.1987076 37.0808296
86.1187210 37.0627403
END
27
84.2545547 36.5953712
84.2568436 36.5954170
84.2614975 36.6027260
84.2429657 36.6132660
84.2899017 36.6484680
84.3137283 36.6776543
84.3274002 36.7127571
84.3326569 36.7615738
END
29
85.2421417 36.9288216
85.2825165 36.8975639
85.2598724 36.8804283
85.2458725 36.8531570
END
30
86.1736374 36.9308853
86.1744843 36.9118576
END
END
定义了两个结构体,和几个变量
struct NODE { double x;
double y; NODE *Nnext;
};
NODE *p1,*q1;
struct Polgon{
NODE *head;
Polgon *next;
};
Polgon *Phead,*p,*q;
点击一个按钮,消息相应函数如下,既读上面的文件,名字为"polygon.txt"
void CPoygonDlg::Oninput()
{
CString str;
CStdioFile myFile;
CFileException fileException;
if(myFile.Open("polygon.txt",CFile::typeText|CFile::modeReadWrite),&fileException){
myFile.SeekToBegin();
myFile.ReadString(str);
CString str1;
double a;
sscanf(str, "%s%lf", &str1, &a);
min_x=a;
myFile.ReadString(str);
sscanf(str, "%s%lf", &str1, &a);
max_x=a;
myFile.ReadString(str);
sscanf(str, "%s%lf", &str1, &a);
min_y=a;
myFile.ReadString(str);
sscanf(str, "%s%lf", &str1, &a);
max_y=a;
myFile.ReadString(str);//有一行空格
myFile.ReadString(str);//读取begin
myFile.ReadString(str);//读取1
Phead=0;开始建立链表,主链表中的data部分是另一个链表的头指针
while(str!="END"){
p=new Polgon;
myFile.ReadString(str);
p->head=0;
while(str!="END"){
p1=new NODE;
double x,y;
sscanf(str, "%lf%lf", &x, &y);
p1->x=x;
p1->y=y;
if(p->head==0){
p->head=p1;q1=p1;}
else {
q1->Nnext=p1;q1=p1;
}
myFile.ReadString(str);
}
if( p->head) q1->Nnext=0;
if(Phead==0){
Phead=p;q=p;}
else{
q->next=p;q=p;
}
myFile.ReadString(str);
}
if(Phead) q->next=0;
} myFile.Close();
}
问题是:编译是没有报错,运行是说内存出错,在myFile.Close();之前加一个breakpiont运行发现之前没错,文件内容全部读进去了,再go提示有unhandled exception
minX 82.290100
maxX 86.682739
minY 36.588001
maxY 39.070396BEGIN
1
85.8959579 38.7232475
85.9086761 38.7299919
END
12
84.0129242 37.8440437
84.0286560 37.8365784
END
14
84.0880280 37.8387718
84.1121826 37.8357544
END
18
86.1660233 37.3344154
86.4753265 37.3189392
END
21
84.5136642 37.3348999
84.2972336 37.1641731
END
23
85.0533371 37.1870651
85.1399384 37.0708580
85.2159576 36.9937019
85.2421417 36.9288216
END
24
86.4000778 37.1655426
86.2833939 37.0844727
86.2305145 37.1057358
86.1987076 37.0808296
86.1187210 37.0627403
END
27
84.2545547 36.5953712
84.2568436 36.5954170
84.2614975 36.6027260
84.2429657 36.6132660
84.2899017 36.6484680
84.3137283 36.6776543
84.3274002 36.7127571
84.3326569 36.7615738
END
29
85.2421417 36.9288216
85.2825165 36.8975639
85.2598724 36.8804283
85.2458725 36.8531570
END
30
86.1736374 36.9308853
86.1744843 36.9118576
END
END
定义了两个结构体,和几个变量
struct NODE { double x;
double y; NODE *Nnext;
};
NODE *p1,*q1;
struct Polgon{
NODE *head;
Polgon *next;
};
Polgon *Phead,*p,*q;
点击一个按钮,消息相应函数如下,既读上面的文件,名字为"polygon.txt"
void CPoygonDlg::Oninput()
{
CString str;
CStdioFile myFile;
CFileException fileException;
if(myFile.Open("polygon.txt",CFile::typeText|CFile::modeReadWrite),&fileException){
myFile.SeekToBegin();
myFile.ReadString(str);
CString str1;
double a;
sscanf(str, "%s%lf", &str1, &a);
min_x=a;
myFile.ReadString(str);
sscanf(str, "%s%lf", &str1, &a);
max_x=a;
myFile.ReadString(str);
sscanf(str, "%s%lf", &str1, &a);
min_y=a;
myFile.ReadString(str);
sscanf(str, "%s%lf", &str1, &a);
max_y=a;
myFile.ReadString(str);//有一行空格
myFile.ReadString(str);//读取begin
myFile.ReadString(str);//读取1
Phead=0;开始建立链表,主链表中的data部分是另一个链表的头指针
while(str!="END"){
p=new Polgon;
myFile.ReadString(str);
p->head=0;
while(str!="END"){
p1=new NODE;
double x,y;
sscanf(str, "%lf%lf", &x, &y);
p1->x=x;
p1->y=y;
if(p->head==0){
p->head=p1;q1=p1;}
else {
q1->Nnext=p1;q1=p1;
}
myFile.ReadString(str);
}
if( p->head) q1->Nnext=0;
if(Phead==0){
Phead=p;q=p;}
else{
q->next=p;q=p;
}
myFile.ReadString(str);
}
if(Phead) q->next=0;
} myFile.Close();
}
问题是:编译是没有报错,运行是说内存出错,在myFile.Close();之前加一个breakpiont运行发现之前没错,文件内容全部读进去了,再go提示有unhandled exception
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货