こんにちは、エラーが発生しましError'unsigned int std::basic_string<char,std::char_traits<char>,std::allocator<char>>::find(_Elem,unsigned int) const' : cannot convert parameter 2 from 'bool (__cdecl *)(char)' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
た。このコードをコンパイルしようとすると、MyWords リストから母音を含む単語を削除し、母音を含まない単語を出力することが目標です。
3 に答える
2
std::string::find
部分文字列を入力として受け取り、最初に一致した文字の位置を返します。
http://en.cppreference.com/w/cpp/string/basic_string/find
ここで直接適用することはできないと思います。
代わりに、次を試してください。
bool vowelPresent = false;
for ( int i = 0; i < word1.size(); i++ )
if ( isVowel( word1[i] ) ) {
vowelPresent = true;
break;
}
if ( !vowelPresent ) {
cout << word1 << endl;
}
または、Adam が提案したように、ヘッダー
でstd::find_if
関数を使用できます。std::string で std::find_if を使用する<algorithm>
于 2013-10-02T09:59:50.113 に答える
1
この行が問題です:
if (word1.find(isVowel) != std::string::npos) {
内で関数ポインタを「見つける」ことはできませんstring
。std::string::find_first_of
次のようなものを使用することをお勧めします。
if (word1.find_first_of("aeiouAEIOU") != std::string::npos) {
あなたの現在のアプローチでは、おそらくどれが述語関数を取るかを考えstd::find_if
ていたでしょう。次のように使用します。
if (std::find_if(std::begin(word1), std::end(word1), isVowel) != std::end(word1) ) { // ...
于 2013-10-02T09:55:53.170 に答える
0
検索述語として使用する場合はisVowel
、次を使用できますstd::find_if
: http://www.cplusplus.com/forum/beginner/393/
于 2013-10-02T09:58:19.877 に答える