← Back to Question List
C++ Quiz #136
vector::at Versus operator[]
scores has three elements. What is true about scores.at(5) compared with scores[5]?
📄 Code
1#include <iostream>2#include <stdexcept>3#include <vector>45int main() {6 std::vector<int> scores = {70, 85, 90};7 try {8 std::cout << scores.at(1) << "\n";9 std::cout << scores.at(5) << "\n";10 } catch (const std::out_of_range&) {11 std::cout << "index 5 is out of range\n";12 }13 return 0;14}