hi all,
i tried this code, but it doesnt work, it says vector subscript out of range:
(sorry, i just dont understand how to correctly post code, if someone could tell me, please?)
#include <iostream>
#include <vector>
using namespace std;
vector<int> v;
v.push_back(1); v.push_back(2);
if (2 < v.size() && v[2] == 3) cout << "doesnt work.";
i understand why it doesnt work, v[2] doesnt exist. my question is: is there an easier way to check the two conditions than do it one after the other in two different (perhaps nested) if-statements, so that the non-existence of v[2] is checked before it can generate an error?
cheers,
richard