loops - C++ comparing iterator with int -
is there simple way compare iterator int?
i have loop this:
for (std::vector<mystruct>::const_iterator = vec->begin(); != vec->end(); ++it)
instead of looping on entire vector, loop on first 3 elements. however, following not compile:
for (std::vector<mystruct>::const_iterator = vec->begin(); < 3; ++it)
it there way achieve same effect?
since it's vector, why not access position directly ?
if (vec->size() > 0) { (int =0; i<3 && i< vec->size(); i++) { // vec[i] can accessed directly //do stuff } }
Comments
Post a Comment