"CL.exe"이(가) 종료되었습니다(코드: 2) 원인

2019. 7. 9. 10:43TIP

컴파일 오류일 가능성이 크다. 경고를 보고 하나씩 지워나가면 해결할 수 있다

 

#include <queue>
#include <cstring>
#include <iostream>
using namespace std;
struct tree {
int p;
int left, right;
tree() : p(-1) {}
tree(int p, int left, int right) : p(p), left(left), right(right) {}
};
tree tr[10001];
int coldata[10001];
int col = 1;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int p, l, r;
tr[p].left = l, tr[p].right = r; // CL.exe
tr[l].p = p, tr[r].p = p;
}
int root;
for (int i = 1; i <= n; i++) {
if (tr[i].p == -1) {
root = i;
}
}
cout << root << '\n';
return 0;
}
view raw clexe.c hosted with ❤ by GitHub

 

예를 들어 초기화하지 않은 변수를 넣었을 때 이러한 오류가 생긴다