将 std::find_if 与 std::string 一起使用
我在这里很愚蠢,但在迭代字符串时,我无法获得将要查找的谓词的函数签名:
bool func( char );
std::string str;
std::find_if( str.begin(), str.end(), func ) )
在这种情况下,谷歌不是我的朋友:(这里有人吗?
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 ) )
In this instance google has not been my friend :( Is anyone here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您试图在 std::string
str
中查找单个字符c
,您可能可以使用std::find()
而不是比std::find_if()
。 而且,实际上,您最好使用std::string
的成员函数string::find()
而不是
中的函数。If your're trying to find a single character
c
within a std::stringstr
you can probably usestd::find()
rather thanstd::find_if()
. And, actually, you would be better off usingstd::string
's member functionstring::find()
rather than the function from<algorithm>
.