zoukankan      html  css  js  c++  java
  • 从vector容器中查找一个子串:search()算法

    如果要从vector容器中查找是否存在一个子串序列,就像从一个字符串中查找子串那样,次数find()与find_if()算法就不起作用了,需要采用search()算法:例子:

    #include "stdafx.h"

    #include <iostream>

    #include <vector>

    #include <algorithm>

    using namespace std;

    int_tmain(int argc, _TCHAR* argv[])

    {

        vector<char> targetVec;

        vector<char> sourchVec;

        targetVec.push_back('');

        targetVec.push_back('2');

        sourchVec.push_back('3');

        sourchVec.push_back('1');

        sourchVec.push_back('');

        sourchVec.push_back('');

        sourchVec.push_back('2');

     

        vector<char>::iterator posIt;

        posIt= search(sourchVec.begin(),sourchVec.end(),targetVec.begin(),targetVec.end());

       

        if(posIt != sourchVec.end())

        {

           cout<<"find it"<<endl;

        }

     

        return 0;

    }

    执行结果:find it

  • 相关阅读:

    模块
    序列化模块
    time模块、os模块、sys模块
    re模块、collections模块、random模块
    正则表达式
    递归函数和二分查找
    匿名函数
    推推导式和内置函数
    Java引用类型与值类型——Java面向对象基础(7)
  • 原文地址:https://www.cnblogs.com/james1207/p/3331427.html
Copyright © 2011-2022 走看看