gpt4 book ai didi

c++ - std::remove 指定元素的 vector

转载 作者:行者123 更新时间:2023-11-28 06:55:02 25 4
gpt4 key购买 nike

我正在尝试删除由 if 语句定义的特定值,然后将其存储为一个 int,然后我想查看该 vector 并通过使用将其删除

if (comparedValuesBetween2[i] == First0ValueFor0Number2[j])
{
//make sure if there are no values to compare left just leave the the while loop by editing the count.
comparedValuesBetween2.resize(std::remove(comparedValuesBetween2.begin(), comparedValuesBetween2.end(), 8) - comparedValuesBetween2.begin());
}

但我收到这些错误,我不知道为什么如果你能帮忙

6 IntelliSense: too many arguments in function call g:\08227 acw\ACW\Sudoku\Sudoku\main.cpp 225

5 IntelliSense: no suitable conversion function from "std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>" to "const char *" exists g:\08227 acw\ACW\Sudoku\Sudoku\main.cpp 225

我是 C++ 的新手。感谢您的帮助。

最佳答案

您可以简单地调用std::vector::erase()从容器中删除指定的元素:

if (comparedValuesBetween2[i] == First0ValueFor0Number2[j])
comparedValuesBetween2.erase(comparedValuesBetween2.begin() + i);

关于c++ - std::remove 指定元素的 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23298036/

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