例如:
vector<string> strs;
strs.push_back("1");
strs.push_back("2");
strs.push_back("3");
strs.push_back("4");
strs.push_back("3");
//strs.removeAllOccurencesOfValue("3");
我找到了这个例子:
但是有没有更简单的方法呢?例如使用 boost 框架?
最佳答案
有一个完美的Erase-remove idiom :
#include <algorithm>
strs.erase( std::remove(strs.begin(), strs.end(), std::string("3")), strs.end() );
关于C++,STL。从 vector<string> 中删除具体值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18533492/