c++ vector insert multiple elements code example
Example 1: add to vector c++
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector;
int myint;
std::cout << "Please enter some integers (enter 0 to end):\n";
do {
std::cin >> myint;
myvector.push_back (myint);
} while (myint);
std::cout << "myvector stores " << int(myvector.size()) << " numbers.\n";
return 0;
}
Example 2: insert into a vector more than once c++
std::vector<unsigned int> array;
array.insert(array.end(), { 1, 2, 3, 4, 5, 6 });