使用std :: find

编程入门 行业动态 更新时间:2024-10-11 05:31:27
本文介绍了使用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

本文发布于:2023-11-30 14:35:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:std   find

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!