int main(void)
{
vector<int> myVector;
myVector.push_back(1);
myVector.push_back(2);
myVector.push_back(3);
// Why should I use this...
for(vector<int>::iterator i = myVector.begin(); i != myVector.end(); ++i)
cout << *i << endl;
// Instead of this?
for(UINT i = 0; i < myVector.size(); ++i)
cout << myVector[i] << endl;
system("PAUSE");
return 0;
}
Proper iteration.
Started by FakeRobotGymnast, Jan 18 2009 04:29 PM
1 reply to this topic
#1
Posted 18 January 2009 - 04:29 PM
I'll just include the code. The question is built-in =P
|
|
|
#2
Posted 18 January 2009 - 07:37 PM
To be honest, I can't name a good reason to prefer iterators over the [] operator, other than to help get you familiar with iterators. The [] operator is not defined for all container types, but iterators are.


Sign In
Create Account


Back to top









