![](/img/trans.png)
[英]Invalid conversion from 'char' to '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.