find_first_of(vs2010)

  • 引言
这是我学习总结 <algorithm>的第十七篇,find_first_of是匹配的一个函数。<algorithm>是c++的一个头文件的名字,里面集成了好多好多的函数。故取之共享于大家,方便大家了解。
  • 作用
find_first_of 的作用是拿指定数据在原数据中去匹配,返回匹配数据在原数据中的首位置。
  • 原型
template<class InputIterator, class ForwardIterator>
InputIterator find_first_of ( InputIterator first1, InputIterator last1,
ForwardIterator first2, ForwardIterator last2)
{
while (first1!=last1) {
for (ForwardIterator it=first2; it!=last2; ++it) {
if (*it==*first1) // or: if (pred(*it,*first)) for version (2)
return first1;
}
++first1;
}
return last1;
}
  • 实验
原数据如下

匹配数据


返回第一个‘A’的位置。
  • 代码
test.cpp
#include <iostream>     // std::cout
#include <algorithm> // std::find_first_of
#include <vector> // std::vector
#include <cctype> // std::tolower bool comp_case_insensitive (char c1, char c2)
{
return (std::tolower(c1)==std::tolower(c2));
} int main ()
{
int mychars[] = {'a','b','c','A','B','C'};
std::vector<char> haystack ( mychars,mychars+6 );
std::vector<char>::iterator it; int needle[] = {'A','B','C'}; // using default comparison:
it = find_first_of (haystack.begin(), haystack.end(), needle, needle+3); if (it!=haystack.end())
std::cout << "The first match is: " << *it << '\n'; // using predicate comparison:
it = find_first_of (haystack.begin(), haystack.end(),
needle, needle+3, comp_case_insensitive); if (it!=haystack.end())
std::cout << "The first match is: " << *it << '\n'; system("pause");
return 0;
}

算法之旅,直奔<algorithm>之十七 find_first_of的更多相关文章

  1. SHA1 安全哈希算法(Secure Hash Algorithm)

    安全哈希算法(Secure Hash Algorithm)主要适用于数字签名标准 (Digital Signature Standard DSS)里面定义的数字签名算法(Digital Signatu ...

  2. 【算法】狄克斯特拉算法(Dijkstra’s algorithm)

    狄克斯特拉算法(Dijkstra’s algorithm) 找出最快的路径使用算法——狄克斯特拉算法(Dijkstra’s algorithm). 使用狄克斯特拉算法 步骤 (1) 找出最便宜的节点, ...

  3. 一文读懂 深度强化学习算法 A3C (Actor-Critic Algorithm)

    一文读懂 深度强化学习算法 A3C (Actor-Critic Algorithm) 2017-12-25  16:29:19   对于 A3C 算法感觉自己总是一知半解,现将其梳理一下,记录在此,也 ...

  4. [转]EM算法(Expectation Maximization Algorithm)详解

    https://blog.csdn.net/zhihua_oba/article/details/73776553 EM算法(Expectation Maximization Algorithm)详解 ...

  5. Floyd判圈算法 Floyd Cycle Detection Algorithm

    2018-01-13 20:55:56 Floyd判圈算法(Floyd Cycle Detection Algorithm),又称龟兔赛跑算法(Tortoise and Hare Algorithm) ...

  6. 蓝桥杯——试题 算法训练 Yaroslav and Algorithm

    试题 算法训练 Yaroslav and Algorithm 资源限制 时间限制:100ms 内存限制:128.0MB 问题描述 (这道题的数据和SPJ已完工,尽情来虐吧!) Yaroslav喜欢算法 ...

  7. 素数算法(Prime Num Algorithm)

    素数算法(Prime Num Algorithm) 数学是科学的皇后,而素数可以说是数学的最为核心的概念之一.围绕素数产生了很多伟大的故事,最为著名莫过于哥德巴赫猜想.素数定理和黎曼猜想(有趣的是,自 ...

  8. 算法之旅,直奔<algorithm>之十三 fill

    fill(vs2010) 引言 这是我学习总结<algorithm>的第十三篇,fill是一个很好的初始化工具.大学挺好,好好珍惜... 作用 fill  的作用是 给容器里一个指定的范围 ...

  9. 算法之旅,直奔<algorithm>之十四 fill_n

    fill_n(vs2010) 引言 这是我学习总结<algorithm>的第十四篇,作为fill的亲兄弟,fill_n也会助你一把的. 作用 fill_n 的作用是给一段指定长度的数据向量 ...

随机推荐

  1. MyBatis 实践 -Mapper与DAO

    MyBatis 实践 标签: Java与存储 MyBatis简介 MyBatis前身是iBatis,是一个基于Java的数据持久层/对象关系映射(ORM)框架. MyBatis是对JDBC的封装,使开 ...

  2. sublime3 常用功能总结

    介绍几个常见的功能: l 自动完成:自动完成的快捷键是Tab和Enter,如果在html文件中,输入cl按下tab或Enter,即可自动补全为class=””:加上zencoding后,更是如虎添翼, ...

  3. Oracle 隔离级别

    From 11gR2: http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/consist.htm#CNCPT621 一. A ...

  4. DB2之隔离级别和锁的论述

    在DB2数据库中, 是通过行级锁和表级锁协调作用来提供较好的并发性, 同时保证数据库中数据的安全. 在DB2中缺省情况下使用行级锁(当然需要IS/IX锁配合),只有当出现锁资源不足, 或者是用命令指定 ...

  5. 一天一个Java基础——排序

    插入排序 直接插入排序: 当插入第i个数据元素k时,由前i-1个数据元素组成已排序的数据序列,将k与数据序列中各数据元素依次进行比较后,插入到数据序列的适当位置,使得插入后的数据序列仍是排序的. 直接 ...

  6. 【转】No JVM could be found on your system解决方法

    原文网址:http://my.oschina.net/liusicong/blog/324964 在安装android studio时,报错: Error launching android Stud ...

  7. ECshop 二次开发模板教程1

    本教程适用于了解 ECshop 和 ECshop模板DIY 以及它们的日常使用,在查看前阁下需要至少会使用一种编辑器(exp:Dreamweaver, editplus, emacs, vi, ee  ...

  8. [Papers]NSE, $\p_3u$, Lebesgue space [Cao, DCDSA, 2010]

    $$\bex \p_3\bbu\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=2,\quad \frac{27}{16}\leq q\le ...

  9. VelocityTracker简单用法

    VelocityTracker顾名思义即速度跟踪,在android中主要应用于touch event, VelocityTracker通过跟踪一连串事件实时计算出 当前的速度,这样的用法在androi ...

  10. 关于【bootstrap】中,【tooltip】的不算bug的bug的个人看法

    先说下遇到这个问题的背景吧. 就是在页面中有个div,这个div右上角(或者其他位置)有个 × 的图标(这个图标添加tooltip工具提示),光标移到这个图标时,触发tooltip,提示“点击移除”这 ...