我在这里很傻但是在迭代字符串时我无法获得谓词的函数签名:
bool func( char );
std::string str;
std::find_if( str.begin(), str.end(), func ) )
Run Code Online (Sandbox Code Playgroud)
在这种情况下谷歌不是我的朋友:(有人在这里吗?
小智 12
#include <iostream>
#include <string>
#include <algorithm>
bool func( char c ) {
return c == 'x';
}
int main() {
std::string str ="abcxyz";;
std::string::iterator it = std::find_if( str.begin(), str.end(), func );
if ( it != str.end() ) {
std::cout << "found\n";
}
else {
std::cout << "not found\n";
}
}
Run Code Online (Sandbox Code Playgroud)