这是代码:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string word="";
getline(cin,word);
word.erase(remove_if(word.begin(), word.end(), isspace), word.end());
word.erase(remove_if(word.begin(), word.end(), ispunct), word.end());
word.erase(remove_if(word.begin(), word.end(), isdigit), word.end());
}
在 VS 2010 中编译时,它工作得非常好。用 G++ 编译它说:
hw4pr3.cpp: In function `int main()':
hw4pr3.cpp:20: error: no matching function for call to `remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
hw4pr3.cpp:21: error: no matching function for call to `remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
hw4pr3.cpp:22: error: no matching function for call to `remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)'