Answers for "back of a vector"

C++
3

c++ vector.back

#include <iostream>
#include <vector>

int main()
{
  std::vector<int> myvector;
  
  //add 2 to the back
  myvector.push_back(2);
  
  std::cout << myvector.back() << std::endl; //this will print 2
  
  myvector.push_back(46);
  std::cout << myvector.back() << std::endl; //prints 46
  
  return 0;
  
}

/*Output
2
46
*/
Posted by: Guest on August-14-2020

Browse Popular Code Answers by Language