C++ beginner learning how to use vectors.
I see that there are 3 ways to iterate through a vector.
If my craps program will: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] << ' ';
- 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


Reply With Quote
Bookmarks