Answers for "c++ vector find first"

C++
5

vector.find()

#include <algorithm>
#include <vector>

if ( std::find(vec.begin(), vec.end(), item) != vec.end() )
   do_this();
else
   do_that();
Posted by: Guest on July-09-2020
0

c++ vector get first element

// vector::front
#include <iostream>
#include <vector>

int main () {

  std::vector<int> myvector;
  myvector.push_back(78);
  myvector.push_back(16);
  // now front equals 78, and back 16
  
  int first = myvector.front(); //first = 78
  std::cout << "the first value in vector is " << first << std::endl;
  return 0;
}
Posted by: Guest on March-11-2021

Browse Popular Code Answers by Language