ALL_OF从'char'到'const char*'的无效转换 [-允许]

ALL_OF invalid conversion from 'char' to 'const char*' [-fpermissive]

本文关键字:char 无效 转换 允许 OF ALL const      更新时间:2023-10-16

编译代码时遇到问题。

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&lt_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),但您正在对一系列chars进行迭代。这些不会转换为std::string。您想要传递类似的谓词

bool IsRoman(char c) {
return ...;
}

pred接受一个字符串,但在表达式pred(*first)中,您向它提供了一个char