Q:

Write a program to initialize a vector from an array of ints

0

Write a program to initialize a vector from an array of ints.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <vector>
#include <iterator>

int main() {
  int ia[] = {1, 2, 3, 4, 5, 6, 7, 8};
  std::vector<int> iv(std::begin(ia), std::end(ia));
  for (const auto &i : iv)
    std::cout << i << ' ';
  std::cout << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now