首页 > 其他 > 详细

find

时间:2021-08-21 08:23:39      阅读:13      评论:0      收藏:0      [点我收藏+]

1. std::find()

template<class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& val)
{
    while (first!=last) {
        if (*first==val) return first;
        ++first;
    }
    return last;
}

注意点:

#include <algorithm> // std::find

假如找不到,返回last,而不是固定的end()!

 

 

2. string::find()

if (str.find("xxx") != string::npos)

从指定位置(index)开始find:str.find("xxx", 3)

 

 

3. STL find

包括map,set,stack,queue等

if (map.find(key) != map.end()) // 假如找到了key

注意:vector竟然没有find() !!!

 

find

原文:https://www.cnblogs.com/Younger-Zhang/p/15168419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!