11.2.1 find_first_of函数
2017-05-27 22:12
204 查看
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++]#
相关文章推荐
- 关于find_first_of函数的疑惑...
- string的erase函数和find、find_first_of函数
- STL(5)find_first_of函数
- STL(5)find_first_of函数
- C++string中的查找函数find与find_first_of函数的区别
- stl string的substr和find_first_of函数的一点心得
- 使用FindFirstFile,FindNextFile遍历一个文件夹
- 使用FindFirstFile,FindNextFile遍历一个文件夹
- 查找算法---find运算,find_first_of的使用
- string 搜索功能 find find_first_of
- C++填坑之std::string::find_first_of
- findfirstfile的问题和遍历目录
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- 错误使用find_last_of函数
- find_first_of()和 find_last_of()
- Windows API——FindFirstFile——查找文件
- C++ STL算法系列2---find ,find_first_of , find_if , adjacent_find的使用
- Windows API一日一练(58)FindFirstFile和FindNextFile函数
- Windows API一日一练(58)FindFirstFile和FindNextFile函数
- 题解LeetCode UglyNumber - FindFirstCommonNode - GetNumberOfK