为什么引发此断言失败警报的向量
why is the vector throwing this assertion failed alert?
我在调试模式下运行我的代码,程序弹出断言失败消息。请帮我找到导致此断言失败的部分。:{
Debug Assertion Failed!
Expression: vector iterators incompatible
法典:
int main()
{
vector<int> a(5);
fill(a.begin(), a.end(), 5);
a[2] = 3;
a[1] = 2; //so now a = {5,2,3,5,5}
auto it = a.begin();
for (; it != a.end();)
{
if (*it == 5)
a.erase(it); //Remove 5
else
it++;
}
copy(a.begin(), a.end(), ostream_iterator<int>(cout, "n"));
}
在迭代过程中擦除时,擦除的迭代器将变为(其他迭代器可能变为)无效:
来得及:
它 = a.erase(it);
相关文章:
- 在VS 2017中,朋友通过具有私有析构函数的结构的unique_ptr向量进行迭代失败
- 引用包装器的向量,push_back失败?
- 嵌套列表(字符串向量的向量)初始化失败
- C++ std::向量插入两个元素替代算法失败
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 使用ENABLE_IF和SFINAE时,功能参数类型扣除(std容器,例如向量)失败
- 测试用例大小为 10 的向量失败
- 向量初始化在 C++ 类中失败
- 与常量 std::string 的向量相关的编译失败
- 为什么引发此断言失败警报的向量
- 每当我输入长度为4的字符串时,下面的cpp代码就会崩溃(向量中的malloc失败)
- push_back包含向量的结构时失败
- 为什么将 cv::Mat 的列复制到向量中会失败
- 提升精神业力 - 具有约束和传播失败的字符串的输出向量
- 代码失败在向量的数据之前插入数字
- ViennaCL:矩阵向量积失败
- LAPACK计算特征向量失败
- c++向量排序方法编译失败,返回预期表达式
- deque的问题:map<...,deque<> >失败,但向量和列表不是?
- 将元素追加到向量会导致后续排序失败