`命令在使用'cin'时终止'` 我用C++ 11编写一个简单的代码,但是遇到了代码>命令,如果我设置了特定的值,则终止< 错误。
代码是:`命令在使用'cin'时终止'` 我用C++ 11编写一个简单的代码,但是遇到了代码>命令,如果我设置了特定的值,则终止< 错误。,c++,cin,C++,Cin,代码是: #include <iostream> using namespace std; int main(){ int r, c; cin >> r >> c; int **Data = new int*[r+2](); for(int i=0; i < c+2; i++){ Data[i] = new int[c+2](); } // Input Data for(int
#include <iostream>
using namespace std;
int main(){
int r, c;
cin >> r >> c;
int **Data = new int*[r+2]();
for(int i=0; i < c+2; i++){
Data[i] = new int[c+2]();
}
// Input Data
for(int n=1; n<r+1; n++){
for(int m=1; m<c+1; m++){
cin >> Data[n][m];
}
}
return 0;
}
但是,如果我输入特定值,则会发生冲突:
clang++ -std=c++11 -stdlib=libc++ test2.cpp -o test2.out
./test2.out
5 1
1
2
3
Command terminated
为什么会发生这种情况???您在这里使用了错误的上限:
for(int i=0; i < c+2; i++){
for(int i=0;i
应该是:
for(int i=0; i < r+2; i++){
for(int i=0;i
您在此处使用了错误的上限:
for(int i=0; i < c+2; i++){
for(int i=0;i
应该是:
for(int i=0; i < r+2; i++){
for(int i=0;i