我的使用-摘要:
int k = 0;
vector<vector<int>>res;
res[k].push_back(val);
报错:
Line 1037: Char 9: runtime error: reference binding to null pointer of type 'std::vector<int, std::allocator<int>>' (stl_vector.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_vector.h:1046:9
根因:vector在还没有分配任何空间时还不能像数组一样用下标形式去访问vector的(v[0]也不行)!!!否则编译通过但报运行错误runtime error!
所有类似runtime error: reference binding to null pointer of type ‘int‘ (stl_vector.h)的报错,都可以来看看-CSDN博客