Q:

Write a program that fetches the first element in a vector using at, the subscript operator, front, and begin. Test your program on an empty vector

0

Write a program that fetches the first element in a vector using at, the subscript operator, front, and begin. Test your program on an empty vector.

All Answers

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

#include <vector>
#include <iostream>

int main() {
  std::vector<int> vi;

  // All of them will cause program terminate in VS2015.
  //int i1 = vi.at(0);
  //int i2 = vi[0];
  //int i3 = vi.front();
  //int i4 = *vi.begin();

  //std::cout << i1 << " " << i2 << " " << i3 << " " << i4 << 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