【发布时间】:2014-01-20 08:59:15
【问题描述】:
我在 DEV C++ 和 Code Blocks 测试过,结果是一样的。在控制台上,当我按下 Enter 按钮时,我看到“名称已停止工作”。
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
using namespace std;
struct ll {
int value;
ll * next;
};
int main() {
int n;
ll a;
cin>>n;
a.value=n;
ll cur;
cur=a;
// error is something here
while (n!=0){
cin>>n;
cur=*cur.next;
cur.value=n;
}
// has stopped working
system("pause");
return 0;
}
【问题讨论】:
-
你的 cur 的 next 没有初始化,它可能包含几乎任何东西,它可能指向你不允许写入的内存部分。初始化你的变量!
-
system("pause")!!!我的眼睛在流血!
标签: c++ data-structures linked-list