-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchUsingFind.cpp
More file actions
41 lines (33 loc) · 803 Bytes
/
SearchUsingFind.cpp
File metadata and controls
41 lines (33 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* \file SearchUsingFind.cpp
* \brief
*
* \todo
*/
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
int main()
{
std::list<std::string> listOfStrs = {
"is", "of",
"the", "Hi",
"Hello", "from" };
// Check if an element exists in list
// Create a list Iterator
std::list<std::string>::iterator it;
// Fetch the iterator of element with value 'the'
it = std::find(listOfStrs.begin(), listOfStrs.end(), "the");
// Check if iterator points to end or not
if(it != listOfStrs.end())
{
// It does not point to end, it means element exists in list
std::cout<<"'the' exists in list "<<std::endl;
}
else
{
// It points to end, it means element does not exists in list
std::cout<<"'the' does not exists in list"<<std::endl;
}
}