Q:

Write a program to create a vector with ten int elements. Using an iterator, assign each element a value that is twice its current value. Test your program by printing the vector

0

Write a program to create a vector with ten int elements. Using an iterator, assign each element a value that is twice its current value. Test your program by printing the vector.

All Answers

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

#include <iostream>
#include <vector>

int main() {
  std::vector<int> iv(10);
  for (int i = 0; i != 10; ++i)
    std::cin >> iv[i];
  for (auto it = iv.begin(); it != iv.end(); ++it)
    *it *= 2;
  for (const auto & elem : iv)
    std::cout << elem << " ";
  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