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

标签 c++ vector

我正在尝试删除由 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/

相关文章:

c++ - vector 复制值

c++ - 指向 vector 迭代器返回值的指针

C++ vector 类抛出异常

c++ - 在 MFC 中填充下拉列表

c++ - GCC - 将宏用于函数属性时出现 "has initializer but incomplete type"错误

c++ - 模板化的成员函数可以实现两个基类的虚函数吗?

c++ - 如何以通用方式交换两个值?

c++ - std::vector 与一位读者和一位作者的多线程同步:仅在调整大小时锁定

c++ - 在 C++ 中将类实例添加到对象层次结构的问题

c++ - 创建动态变量