xxxxxxxxxx
#include <iostream>
#include <vector>
int main() {
std::vector<int> myVector = {1, 2, 3};
int index = 3; // This would cause an out-of-range error
if (index >= 0 && index < myVector.size()) {
// Accessing the element only if the index is within range
int element = myVector[index];
std::cout << "Element at index " << index << ": " << element << std::endl;
} else {
std::cout << "Error: Index out of range" << std::endl;
}
return 0;
}