本文介绍了使用std :: find_if和std :: string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里很蠢,但是我不能得到函数签名的谓词去迭代字符串的find_if:
I'm being stupid here but I can't get the function signature for the predicate going to find_if when iterating over a string:
bool func( char ); std::string str; std::find_if( str.begin(), str.end(), func ) )$ b
在这个例子中,google不是我的朋友:(这里有人吗?
In this instance google has not been my friend :( Is anyone here?
推荐答案#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"; } }
更多推荐
使用std :: find
发布评论