#include #include #include #include //for out_of_range using namespace std; int main() { int a[] = {10, 20, 30}; const size_t n = sizeof a / sizeof a[0]; vector v(a, a + n); cout << "Please input a subscript: "; vector::size_type i; //data type for a vector subscript cin >> i; try { cout << "Element number " << i << " is " << v.at(i) << ".\n"; } catch (const out_of_range& out) { cerr << "caught out_of_range exception " << out.what() << "\n"; return EXIT_FAILURE; } catch (const exception& e) { cerr << "caught another exception " << e.what() << "\n"; return EXIT_FAILURE; } catch (...) { cerr << "caught unexpected exception\n"; return EXIT_FAILURE; } for (vector::size_type i = 0; i < v.size(); ++i) { cout << v[i] << "\n"; //cout << v.operator[](i) << "\n"; } for (vector::const_iterator it = v.begin(); it != v.end(); ++it) { cout << *it << "\n"; //cout << it.operator*() << "\n"; } return EXIT_SUCCESS; }