ALL_OF从'char'到'const char*'的无效转换 [-允许]
ALL_OF invalid conversion from 'char' to 'const char*' [-fpermissive]
编译代码时遇到问题。
template<class InputIterator, class UnaryPredicate>
bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred)
{
while (first!=last) {
if (!pred(*first)) return false;
++first;
}
return true;
}
我从http://www.cplusplus.com/reference/algorithm/all_of/?kw=all_of.
我正在使用代码::块12.11,我有以下错误:
C:\Users\PC-HP\Desktop\chiffre\romain\main.cpp||在'bool all_of(InputIterator,InputIterater,UnaryPredicate)的实例化中[带有InputIterator=__gnu_cx::__normal_iterator>;UnaryPredictate=bool(*)(std::basic_string)]':|
C: \Users\PC-HP\Desktop\chiffre\romain\main.cpp|84|此处需要|
C: \Users\PC-HP\Desktop\chiffre\romain\main.cpp|13|错误:从"char"到"const char*"的转换无效[-fpermission]|
c: \program files\codeblocks\mingw\bin。。\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.tcc|214|错误:初始化'std::basic_string<_CharT,_Traits,_Alloc>::basic_string(const_CharT*,const_Alloc&)[其中_CharT=char;_Traits=std::char_Traits;_Alloc=std::分配器]'[-fpermission]|
||===构建完成:2个错误,2个警告(0分1秒)===|
第84行:
while(!all_of(romain.begin(), romain.end(), IsRoman))
这是我的全部代码:http://pastebin.com/k0KYNB6H我不使用c++11
。
根据您的错误消息,您的谓词采用std::basic_string
(可能实际上是std::string
),但您正在对一系列char
s进行迭代。这些不会转换为std::string
。您想要传递类似的谓词
bool IsRoman(char c) {
return ...;
}
pred
接受一个字符串,但在表达式pred(*first)
中,您向它提供了一个char
。
- 将 const 转换为 const char* 无效,我该如何解决?使用 gcc7 时失败
- 类型"int"和"const char [15]"到二进制"运算符<<"的无效操作数^
- 错误:从'void*'到'const uint8_t* {aka const unsigned char*}'的转换无效 [-允许]
- 错误:从 'char' 到 'const char' [-允许] strcat(加密,密钥[i])的转换无效;
- C++ - 从 "int" 到 "unsigned char" 的缩小转换无效
- 错误:AES 加密密钥:从"char*"到"无符号字符"的转换无效
- 无法确定为什么函数调用中从 char* 到 char 的无效转换
- 我收到一个错误无效的操作数,类型为 const char [42] 和二进制"运算符+"的双倍数
- 在 sprintf 中从 'signed char*' 到 'char*' 的转换无效
- 在这个简单函数中从'char'到'const char*'的无效转换
- 'const char [26]' 和 'LPSTR ' 类型的无效操作数
- C++从 'const char*' 到 'char*' Arduino Uno 的无效转换
- 如何修复C++中的"错误:从'int'到'const char*'[-fallowive]的无效转换?
- 将文本文件读取为 const char* 有时有效,有时无效
- C++:"错误:类型'const char*'和'const char [28]'的操作数无效到二进制'ope
- C++错误:从"char"到"const char*"的转换无效[-允许]
- 从'const char**'到'char* const*'的转换无效
- 从 'char' 到 'char*' strcat 函数的转换无效
- 使用表达式初始化char*无效
- 简单的 int 到字符串转换..int to const char* 无效