vector<int> input = {1, 2, 3, 4, 17, 117, 517, 997};
cout<< "input vector at index -1 is: " << input[-1] <<endl;
Using the above the code, the result will be: input at index -1 is: 0. However, if we use follwoing :
vector<int> input = {1, 2, 3, 4, 17, 117, 517, 997};
cout<< "input vector at index -1 is: " << input.at(-1) <<endl;
The result would be : input at index -1 is: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector.
Can some one explain the reason to me? Thank you.