11.2.1 find_first_of函数
来源:互联网 发布:网站注册域名查询 编辑:程序博客网 时间:2024/06/13 11:54
find_first_of的参数:
这个算法带有两对迭代器参数来标记两段元素范围,
在第一个范围内查找与第二段范围中任意元素匹配的元素,然后返回一个迭代器,指向第一个匹配的元素。
如果找不到匹配的元素,则返回第一个范围内的end迭代器。
这个算法带有两对迭代器参数来标记两段元素范围,
在第一个范围内查找与第二段范围中任意元素匹配的元素,然后返回一个迭代器,指向第一个匹配的元素。
如果找不到匹配的元素,则返回第一个范围内的end迭代器。
[root@localhost testc++]# vi find_first_of.cpp
1 #include <iostream>
2 #include <algorithm>
3 #include <numeric>
4 #include <list>
5 #include <string>
6 using namespace std;
7
8 int main()
9 {
10 // program for illustration purposes only:
11 // there are much faster ways to solve this problem
12 size_t cnt = 0;
13 string sval;
14 list<string> roster1;
15 list<string> roster2;
16 cout << "Enter roster1 : " << endl;
17 while( cin >> sval)
18 roster1.push_back(sval);
19 cin.clear();//能够进行两个cin输入
20 cout << "Enter roster2 : " << endl;
21 while( cin >> sval)
22 roster2.push_back(sval);
23 list<string>::iterator it = roster1.begin();
24 // look in roster1 for any name also in roster2
25 while ((it = find_first_of(it,roster1.end(),
26 roster2.begin(),roster2.end()))
27 != roster1.end()) {
28 ++cnt;
29 // we got a match ,increment it to look in the rest of roster1
30 ++it;
31 }
32 cout << "Found " << cnt
33 << " names on both roster2" << endl;
34 return 0;
35 }
[root@localhost testc++]# g++ find_first_of.cpp
[root@localhost testc++]# ./a.out
Enter roster1 :
aa
bb
Enter roster2 :
bb
cc
Found 1 names on both roster2
[root@localhost testc++]#
阅读全文
0 0
- 11.2.1 find_first_of函数
- C++ 11.2 accumulate、find_first_of 函数
- STL(5)find_first_of函数
- 函数find_first_of()和 find_last_of()
- 关于find_first_of函数的疑惑...
- find_first_of
- find_first_of
- find_first_of
- find_first_of
- find_first_of
- find_first_of
- string 中find_first_of()函数用法例题
- strrchr与strchr函数 find_first_of与find_last_of
- CString中find_first_of和find_last_of()函数
- 20170604_string中的函数find_first_of()和 find_last_of()
- string类中find(),find_first_of()和find_first_not_of()函数
- string类成员函数find/find_first_of用法详解
- stl string的substr和find_first_of函数的一点心得
- Android Mvp架构设计与性能优化
- node.js(1) 环境安装
- node.js(3) 异步式 I/O 与事件式编程
- 11-1.cpp
- 11.2.1 只读算法
- 11.2.1 find_first_of函数
- fill -11.2.2写容器的算法
- sizeof和strlen区别
- Unity中动态改变物体的Material(Shader)
- 不检查写入操作的算法 11.2.2-写容器的算法
- java中四种访问修饰符
- back_inserter 11.2.2- 3 插入迭代器
- make 死循环的问题
- Proxies 与 Agents 的认识