此代码中的 std::remove_if 有什么问题
what's wrong with std::remove_if in this code
solution.cc:1:47:错误:调用"remove_if(std::basic_string::迭代器,std::asic_string::迭代器("时没有匹配的函数
#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;
}
我尝试在g++ 4.9.1
中编译您的代码。准确的错误是:
在函数
int main()
中:错误:没有匹配的函数用于调用"remove_if(std::basic_string::迭代器,std::asic_string::迭代器,未解析的重载函数类型(">
您对std::transform
的调用没有发生这种情况,因为您实际上指定了正在使用的tolower
。
isspace
在全局名称空间和名称空间std
中都有定义,所以当您有using namespace std
,而您编写isspace
时,会出现歧义。具体来说,<cctype>
中有一个过载,<locale>
中定义了另一个过载。
只要写::isspace
就可以了。
相关文章:
- 使用枚举作为条件,if 条件将返回什么,真或假?
- 什么可以用来替换代码中的循环和 if 语句?
- 这个 FOR-IF 循环的解释是什么?
- if(i | j) 和 if (i & j) 在C++中做什么
- 在 if 语句中处理多个 or 的更优雅的方法是什么
- de if-Block 是什么意思
- if 语句正在检查什么条件
- 有什么更好的表现?IF或正常循环的不定循环
- if(!pointer) 和 if(!*pointer) 有什么区别?
- 前循环后的if stategent是什么意思
- C++:无论如何,有什么可以知道是什么触发了 If 语句
- 关于"if" "elseif" "else"陈述的良好做法是什么
- 在 c++ 中使用两个 if 有什么区别吗
- 不必要的 else 语句:当可以使用 IF 时,使用 ELSE IF 有什么缺点吗?
- "[Error] expected unqualified-Id before 'if'"这个代码块是什么意思
- 打印此矩阵的 if 语句是什么
- 我的 if 语句逻辑出了什么问题?
- 同时执行 if 和 else 条件的逻辑是什么
- if(NULL==指针)和if(指针==NULL)之间有什么区别
- 这个IF语句有什么问题吗?(C++)