【发布时间】:2014-02-05 13:21:40
【问题描述】:
我有以下代码:
#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’
我发现了this 的问题,但是根据cppreference,没有任何版本的这个函数接受两个参数。我也发现了this 问题,但根据 cppreference(是的,再次),我看到只有一个 std::isspace 函数重载。
谁是对的?我究竟做错了什么?我该如何解决?
【问题讨论】:
-
Here's the other
std::isspaceon cppreference。不幸的是 cppreference 的搜索没有找到两者。 -
@dyp 搜索不会,但每个页面底部的“另请参阅”链接到另一个页面。