What is the difference between a const_iterator and an iterator and where would you use one over the other?
ok Let me explain it with very simple example first without using constant iterator consider we have collection of random integers collection "randomData"
for(vector::iterator i = randomData.begin() ; i != randomData.end() ; ++i)*i = 0;
for(vector::const_iterator i = randomData.begin() ; i!= randomData.end() ; ++i)cout << *i;
As can be seen for writing/editing data inside collection normal iterator is used but for reading purpose constant iterator has been used . If you try using constant iterator in first for loop you will get error . As a thumb rule use constant iterator to read data inside collection .