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. bzoj2326: [HNOI2011]数学作业

    矩阵快速幂,分1-9,10-99...看黄学长的代码理解...然而他直接把答案保存在最后一行(没有说明...好吧应该是我智障这都不知道... #include<cstdio> #inclu ...

  2. Sciter/HTMLayout内存占用评测

    先从最基础的Exe文件的执行说起: Exe文件要在系统中执行,首先要将Exe文件本身加载入内存中,并且通常在内存中加载完成的Exe所占空间大小会比实际所占的磁盘空间大一些,这是由内存的特殊设定所决定的 ...

  3. Java [Leetcode 144]Binary Tree Preorder Traversal

    题目描述: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given bin ...

  4. Java [Leetcode 290]Word Pattern

    题目描述: Given a pattern and a string str, find if str follows the same pattern. Here follow means a fu ...

  5. Mac 配置jdk

    1.打开终端,开始操作 cd ~touch.bash_profile vi .bash_profile 2.在此文本中添加以下内容 export JAVA_HOME=/Library/Java/Jav ...

  6. Ruby 文件处理

    #r read, #w write, #a append, #r+ 读写方式 从文件的头位置开始读取或写入, #w+ 读写方式,如果文件已存在清空该文件,不存在就创建一个新的文件, #a+ 如果文件存 ...

  7. Ruby基础数据类型

    #数字分为证书Integer,浮点数Float(对应与其他语言中的double),和复数Complex #整数又分为Fixnum和Bignum,Fixnum和Bignum会互相转换,这些都是ruby自 ...

  8. CocoaPods一个Objective-C第三方库的管理利器

    转:http://blog.csdn.net/totogo2010/article/details/8198694 介绍: 开发应用的时候第三方的库是不可缺少的,能提高开发的效率. 一些经常用到的库, ...

  9. ZOJ 3879 Capture the Flag

    以此题纪念我写的第一篇acm博客,第一道模拟:) http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3879 题意非常复杂,感觉 ...

  10. ASP.NET常用加密解密方法

    ASP.NET常用加密解密方法 一.MD5加密解密 1.加密 C# 代码           public static string ToMd5(string clearString)        ...