Wednesday, 28 February 2018

For Loop in STL C++

Different ways of writing for loop to loop through vectors in c++

vector<int> v;

for(int &t:v)
   cout<<t;

for(int i=0;i<v.size();i++)
     cout<<v[i];

vector<int>::iterator it;
for(it=v.begin();it != v.end();it++)
     cout<<*it;

No comments:

Post a Comment