std::remove_if
template<class ForwardIterator, class UnaryPredicate>
ForwardIterator remove_if(ForwardIterator first,ForwardIterator last,UnaryPredicate pred);
作用:在algorithm头文件中,将[first,last)这个区域中的某些元素(对于pred方法为true的元素)移去,并返回一个iterator(指向新的区域的past-the-end元素)
这个方法并不会改变container的大小,只是会用紧接着的元素来替代那些要remove掉的元素
用法:
word.erase(std::remove_if(word.begin(),word.end(),ispunct),word.end());
// remove the punctuation character in a string
本文详细介绍了C++标准库中的std::remove_if算法。该算法用于移除[first,last)区间内满足特定条件的元素,同时不会改变容器的实际大小。文章通过示例展示了如何使用std::remove_if去除字符串中的标点符号。
2960

被折叠的 条评论
为什么被折叠?



