find function in c++ code example

Example 1: find function in c++

// find function for strings
// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
str = "Ilayathapathy";
subStr = "thalapathy";
cout << str.find(subStr, 1);  // prints 5 (first occurrence of substring \n
// starting at index 1

Example 2: vector.find()

#include <algorithm>
#include <vector>

if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
   do_this();
else
   do_that();

Example 3: find in string c++

size_t find (const string& str, size_t pos = 0) const;

Tags:

Cpp Example