s find c 2b 2breference

Solutions on MaxInterview for s find c 2b 2breference by the best coders in the world

showing results for - "s find c 2b 2breference"
Valentina
13 Oct 2017
1// find example
2#include <iostream>     // std::cout
3#include <algorithm>    // std::find
4#include <vector>       // std::vector
5
6int main () {
7  // using std::find with array and pointer:
8  int myints[] = { 10, 20, 30, 40 };
9  int * p;
10
11  p = std::find (myints, myints+4, 30);
12  if (p != myints+4)
13    std::cout << "Element found in myints: " << *p << '\n';
14  else
15    std::cout << "Element not found in myints\n";
16
17  // using std::find with vector and iterator:
18  std::vector<int> myvector (myints,myints+4);
19  std::vector<int>::iterator it;
20
21  it = find (myvector.begin(), myvector.end(), 30);
22  if (it != myvector.end())
23    std::cout << "Element found in myvector: " << *it << '\n';
24  else
25    std::cout << "Element not found in myvector\n";
26
27  return 0;
28}