This may be me overlooking something basic, but the code below has no output or exceptions shown in my terminal. (using g++ in Cygwin) First Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
cout << "main";
vector<string> v;
v.at(0)= "HI";
return 0;
}
Second Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
cout << "main" <<endl;
vector<string> v;
try{
v.at(0)= "HI";
}catch(const std::exception &exc){
cout << exc.what()<<endl;
}
return 0;
}
which has the expected output of :
main
vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
is there a reason why the first code doesn't give an exception or any output?