Answers for "how to begin a vector in c++"

C++
-2

how to begin a vector in c++

// vector::begin/end
#include <iostream>
#include <vector>

int main ()
{
  std::vector<int> myvector;
  for (int i=1; i<=5; i++) myvector.push_back(i);

  std::cout << "myvector contains:";
  for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}
Posted by: Guest on March-09-2021

Code answers related to "how to begin a vector in c++"

Browse Popular Code Answers by Language