// Code derived from Stroustrup's PPP2 book// § 5.6.2 Range errors// -and beginning on p 149#include<iostream>#include<stdexcept>#include<string>#include<vector>usingstd::cerr;usingstd::cin;usingstd::cout;usingstd::out_of_range;usingstd::to_string;usingstd::vector;intmain()try{cout<<"Please enter integers: (press '|' to stop):\n";vector<int>v;// a vector of intsfor(intx;cin>>x;)v.push_back(x);// set values// print valuesfor(unsignedinti=0;i<=v.size();++i){// exposition only:// if (v.size() <= i) // check the index i against the vector size// throw out_of_range{to_string(i)};cout<<"v["<<i<<"] == "<<v[i]<<'\n';}}catch(out_of_range&){cerr<<"Oops! Range error\n";return1;}catch(...){// catch all other exceptionscerr<<"Exception: something went wrong\n";return2;}