gpt4 book ai didi

c++ - STL 迭代器 : Assertion Error

转载 作者:行者123 更新时间:2023-11-28 07:51:31 26 4
gpt4 key购买 nike

为什么以下代码会产生断言错误:Expression: list iterators incompatible

#include <list>
using namespace std;

int main()
{
list<int> a;
a.push_back(1);
list<int>::iterator iter=a.begin();
a.erase(iter);

iter==a.end();
}

最佳答案

你想要做的是这样的:

#include <list>
using namespace std;

int main()
{
list<int> a;
a.push_back(1);
list<int>::iterator iter=a.begin();
iter = a.erase(iter);
}

关于c++ - STL 迭代器 : Assertion Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13671824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com