小编San*_*icu的帖子

如何从 C++ 中的 for 循环内的列表中删除

有没有办法删除循环遍历该列表的 for 循环中的列表项?例子:

std::list<int> myList;
myList.push_back(5);
myList.push_back(8);

std::list<int>::iterator i;

for (i = myList.begin(); i != myList.end(); i++)
{
    if (i == 8)
        // myList.remove(*i);
}
Run Code Online (Sandbox Code Playgroud)

有什么办法可以myList.remove(*i)用其他东西替换,因为那会产生错误。

c++ list

0
推荐指数
1
解决办法
87
查看次数

标签 统计

c++ ×1

list ×1