Q:

How would you initialize a vector<double> from a list<int>? From a vector<int>? Write code to check your answers

0

How would you initialize a vector<double> from a list<int>? From a vector<int>? Write code to check your answers. 

All Answers

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

#include <vector>
#include <list>
#include <iostream>

int main() {
  std::list<int> li{1, 2, 3};
  std::vector<int> vi{4, 5, 6};

  std::vector<double> vd1(li.begin(), li.end());
  std::vector<double> vd2(vi.begin(), vi.end());

  std::cout << vd1[0] << " " << vd2[0] << 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