快速或安全的访问std::vector实例的方法
How to do it...
#include <iostream> #include <vector> using namespace std; int main() { const size_t container_size{1000}; vector<int> v(container_size, 123);cout << "Out of range element value: " << v[container_size + 10] << '\n';cout << "Out of range element value: " << v.at(container_size + 10) << '\n'; }Out of range element value: -726629391 terminate called after throwing an instance of 'std::out_of_range' what(): array::at: __n (which is 1010) >= _Nm (which is 1000) Aborted (core dumped)
How it works...
There's more...
Last updated