Debug Assertion Failed
Expression: vector subscript out of range出现上面的弹窗,导致程序崩溃,如何让系统不崩溃呢。答:使用vec.at(i)。
有问题的程序
i#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> aa(5);
for (int i = 0; i < 6; ++i) // 超出了vector的范围了
{
std::cout << aa[i] << std::endl; // 方式1
std::cout << *(aa.begin() + i) << std::endl; // 方式2
std::cout << aa.at(i) << std::endl; // 方式3
}
printf("==========\n");
return 0;
}
出现的问题
方式一报错
方式二报错