I have just started learning vectors and iterators. I can't understand 2 things. Why can I change the constant iterator and what is the role of the "*"?
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> inventory;
inventory.push_back("inventory1");
inventory.push_back("inventory2");
inventory.push_back("inventory3");
vector<string>::iterator myIterator;
vector<string>::const_iterator iter;
cout << "Your items:\n";
for (iter = inventory.begin(); iter != inventory.end(); iter++)
{
cout << *iter << endl;
}
const. Aconst_iteratorrefers to the object being "pointed to" asconst. The*is to retrieve the value the iterator "points" to.const_iteratordoesn't mean that the iterator is a constant, but that you cannot change the item it refers to.