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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -