#include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string s; std::getline(cin, s); std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::remove_if(s.begin(), s.end(), isspace); // cout<<s; int len=s.length(); len=len+90; bool temp; bool value[len]; for(int i=0;i<len;i++) { int x=(int)s[i]; if(value[x]!=1) value[x]=1; } for(int i=65;i<=90;i++) if(value[i]==1) {temp=true;continue;} else {temp=false;break;} if(temp) cout<<"pangram"<<endl; else cout<<"not pangram"<<endl; return 0; }solution.cc:14:47:错误:没有匹配函数来调用'remove_if(std :: basic_string :: iterator,std :: basic_string :: iterator,)'
#include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string s; std::getline(cin, s); std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::remove_if(s.begin(), s.end(), isspace); // cout<<s; int len=s.length(); len=len+90; bool temp; bool value[len]; for(int i=0;i<len;i++) { int x=(int)s[i]; if(value[x]!=1) value[x]=1; } for(int i=65;i<=90;i++) if(value[i]==1) {temp=true;continue;} else {temp=false;break;} if(temp) cout<<"pangram"<<endl; else cout<<"not pangram"<<endl; return 0; }solution.cc:14:47: error: no matching function for call to 'remove_if(std::basic_string::iterator, std::basic_string::iterator, )'
最满意答案
我尝试在g++ 4.9.1编译代码。 确切的错误是:
在函数int main() :error:没有匹配函数用于调用'remove_if(std :: basic_string :: iterator,std :: basic_string :: iterator,unresolved overloaded function type)'
调用std::transform时没有发生这种情况,因为你实际上指定了你正在使用哪个tolower 。
在全局命名空间和命名空间std都定义了isspace ,因此当你using namespace std并编写isspace ,就会产生歧义。 具体来说, <cctype>有一个重载, <locale>有另一个重载。
只要写::isspace就可以了。
I tried compiling your code in g++ 4.9.1. The exact error is:
In function int main(): error: no matching function for call to 'remove_if(std::basic_string::iterator, std::basic_string::iterator, unresolved overloaded function type)'
This didn't happen with your call to std::transform because you actually specified which tolower you're using.
isspace is defined both in the global namespace and in namespace std, so when you have using namespace std, and you write isspace, there's an ambiguity. To be specific, there's one overload in <cctype> and another defined in <locale>.
Just write ::isspace and you're good to go.
更多推荐
发布评论