繁体   English   中英

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

[英]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中获取了代码。

我正在使用Code :: blocks 12.11,并且出现以下错误:

C:\\ Users \\ PC-HP \\ Desktop \\ chiffre \\ romain \\ main.cpp ||在'bool all_of(InputIterator,InputIterator,UnaryPredicate)的实例中[使用InputIterator = __gnu_cxx :: __ normal_iterator>; UnaryPredicate = 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 *'的无效转换[-fpermissive] |

c:\\ program files \\ codeblocks \\ mingw \\ bin .. \\ lib \\ gcc \\ mingw32 \\ 4.7.1 \\ include \\ c ++ \\ bits \\ basic_string.tcc | 214 |错误:正在初始化'std :: basic_string <_CharT的参数1, _Traits,_Alloc> :: basic_string(const _CharT *,const _Alloc&)[with _CharT = char; _Traits = std :: char_traits; _Alloc = std :: allocator]'[-fpermissive] |

|| ===构建完成: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的序列。 这些不会转换为std::string 您想传递一个谓词,例如

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

pred需要一个字符串,但是在表达式pred(*first)您将其喂入一个char

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM