【发布时间】:2012-02-28 00:58:52
【问题描述】:
vector<Flight> flights;
while (!myReadFile.eof()) {
flights.push_back(*(new Flight()));
// read some info...
}
在第二个循环之后,程序崩溃并显示以下消息:
“cpi.exe 中 0x776315de 处未处理的异常:0xC0000005:访问冲突读取位置 0xfeeefee2。”
我该如何解决这个问题?
编辑:
vector<Flight> flights;
while (!myReadFile.eof()) {
flights.push_back(Flight());
// read some info...
}
我试过这个,但仍然在第二个循环中崩溃
编辑:完整而
int count = 0;
myReadFile >> output;
while (!myReadFile.eof()) {
flights.push_back(Flight());
flights[count].setFlightNum(atoi(output));
myReadFile >> output;
int x = atoi(output);
flights[count].setStartX(x);
myReadFile >> output;
int y = atoi(output);
flights[count].setStartY(y);
count++;
myReadFile >> output;
}
【问题讨论】:
-
你能告诉我们
Flight的构造函数(默认和副本)吗? -
它是一个空的构造函数——所有的成员都是整数或浮点数。没有复制构造函数
-
这是一个现场项目吗?只是对我们在天空中的朋友的友好关心。
-
你能发布
while循环的其余部分吗? -
@user1027958:那么我真的怀疑它在将元素插入向量时是否崩溃,看起来崩溃是在while循环中的其他地方。