zoukankan      html  css  js  c++  java
  • c++ 匹配A容器中最先出现的b容器中的元素,返回iterator,(find_first_of)

    #include <iostream>     // std::cout
    #include <algorithm>    // std::find_first_of
    #include <vector>       // std::vector
    #include <cctype>       // std::tolower
    using namespace std;
    bool comp_case_insensitive (char c1, char c2) {
      return (tolower(c1)==tolower(c2));
    }
    
    int main () {
      int mychars[] = {'a','b','c','A','B','C'};
      vector<char> haystack (mychars,mychars+6);
      vector<char>::iterator it;
    
      int needle[] = {'C'};
    
      // using default comparison:
      it = find_first_of (haystack.begin(), haystack.end(), needle, needle+3);
      cout << "The first match is: " << *it << '
    ';
      if (it!=haystack.end())
        cout << "The first match is: " << *it << '
    ';
    
      // using predicate comparison:
      it = find_first_of (haystack.begin(), haystack.end(),needle, needle+3, comp_case_insensitive);
      cout << "The first match is: " << *it << '
    ';
      if (it!=haystack.end())
        cout << "The first match is: " << *it << '
    ';
    
      return 0;
    }
  • 相关阅读:
    c8051f交叉开关
    8052定时器2的用法
    poj1010
    poj2101
    poj1958
    poj3444
    poj2977
    DataTable 相关操作
    C#中string和StringBuilder的区别
    DataTable排序,检索,合并,筛选
  • 原文地址:https://www.cnblogs.com/sea-stream/p/9823594.html
Copyright © 2011-2022 走看看