iterator demo

来源:互联网 发布:webhook php自动部署 编辑:程序博客网 时间:2024/05/18 02:17
#include <iostream>#include <vector>bool find(std::vector<int>::iterator beg, std::vector<int>::iterator end, int target);int main(){    std::vector<int> ivec = {1, 2, 100, 99, 22};    int target = 101;    std::cout << std::boolalpha << find(ivec.begin(), ivec.end(), target) << std::endl;    return 0;}bool find(std::vector<int>::iterator beg, std::vector<int>::iterator end, int target){    while (beg != end) {        if (*beg++ == target) return true;    }    return false;}

0 0
原创粉丝点击