部分代码如下:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
ios_base::sync_with_stdio(0);
unsigned long k,p,q, all;
cin >> k >> p >> q;
vector<long> klo(k);
all = 0;
for(unsigned long i = 0;i<k;i++){
scanf("%d", &klo[i]);
all += klo[i];
}
vector<unsigned long> stack(all);
stack[1] = 1;
stack.at(2) = 2;
....REST OF THE CODE....
return 0;
}
它在 Windows 和 Linux 上编译。在 Windows 上工作没有问题,但是当我尝试在 Linux 上运行它时 stack[1] = 1;
显示 Error: signal: 11
和 stack.at( 2) = 2;
: 错误: signal:6
有什么问题?
@EDIT:我发现 all
变量是空的。似乎 all += klo[i];
没有返回正确的值。但不知道为什么这段代码在 Windows 中有效
最佳答案
当 vector<unsigned long> stack(all);
达到了,似乎all
为 0。
关于c++ - std::vector 赋值 SIGNAL 11 和 SIGNAL 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19742536/