Q:

Using fill_n, write a program to set a sequence of int values to 0

0

Using fill_n, write a program to set a sequence of int values to 0.

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::vector<int> vi(10, 1);
  std::list<int> li(10, 1);
  std::fill_n(vi.begin(), vi.size(), 0);
  std::fill_n(li.begin(), li.size(), 0);
  std::cout << vi.back() << " " << li.back() << 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