I have the following code:
#include <algorithm>
#include <cctype>
#include <string>
int main()
{
std::string str;
str.erase(std::remove_if(str.begin(), str.end(), std::isspace), str.end());
}
使用 MSVC-11.0 编译此代码时没有任何错误,但是 gcc 4.7.2 给出了以下错误:
main.cpp: In function ‘int main()’:
main.cpp:8:66: error: no matching function for call to ‘remove_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)’
main.cpp:8:66: note: candidate is:
In file included from /usr/include/c++/4.7/algorithm:63:0,
from main.cpp:1:
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note: template<class _FIter, class _Predicate> _FIter std::remove_if(_FIter, _FIter, _Predicate)
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note: template argument deduction/substitution failed:
main.cpp:8:66: note: couldn't deduce template parameter ‘_Predicate’
我发现关于这个问题有这篇问题,但根据cppreference,没有任何一个带有两个参数的版本。我还发现了这篇问题,但是根据cppreference(是的,再次是它),我只看到了一个std::isspace函数重载。
谁是正确的?我做错了什么?如何修复它?
std::isspace
зҡ„cppreferenceй“ҫжҺҘпјҡhttp://en.cppreference.com/w/cpp/locale/isspaceгҖӮдёҚе№ёзҡ„жҳҜпјҢcppreferenceзҡ„жҗңзҙўеј•ж“Һж— жі•жүҫеҲ°дёӨдёӘй“ҫжҺҘгҖӮ - dyp