C ++按值从向量中删除元素
C++ Remove element from vector by value
我看了一圈,我觉得这个问题的共识答案是这个方法;
template <typename T>
void removeByValue(vector<T> & vec, const T & val)
{
vec.erase(std::remove(vec.begin(), vec.end(), val), vec.end());
}
但是,我在尝试编译时遇到错误 error C2660: 'remove' : function does not take 3 arguments
。为什么会给我这个错误?
std::remove
仅在包含 header <algorithm>
.
时可用
the MSDN documentation here 以及任何 C++ 参考文献都清楚地说明了这一点。
我看了一圈,我觉得这个问题的共识答案是这个方法;
template <typename T>
void removeByValue(vector<T> & vec, const T & val)
{
vec.erase(std::remove(vec.begin(), vec.end(), val), vec.end());
}
但是,我在尝试编译时遇到错误 error C2660: 'remove' : function does not take 3 arguments
。为什么会给我这个错误?
std::remove
仅在包含 header <algorithm>
.
the MSDN documentation here 以及任何 C++ 参考文献都清楚地说明了这一点。