-
November 28th, 2012, 11:32 PM
#1
Vector iterators
C++ beginner learning how to use vectors.
I see that there are 3 ways to iterate through a vector.
Code:
Method 1:
for(vector<int>::iterator it = myVect.begin(); it != myVect.end(); it++)
cout << *it << ' ';
Method 2:
for (vector<int>::size_type i = 0; i < myVect.size(); i++)
cout << myVect[i] << ' ';
Method3:
for (unsigned i = 0; i < myVect.size(); i++)
cout << myVect[i] << ' ';
If my craps program will:
- only ever use the same vector container,
- will have a maximum of 50 elements,
- will only ever be compiled using VC++ 2010 Express,
can I just use method-3 safely? If not, why not?
And actually, with only 50 elements max, couldn't I use "int i = 0" in the for statement instead of unsigned?
Just trying to understand it all.
Thanks,
Raptor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|