Explain why we need both an iterator and a constiteratorSolu

Explain why we need both an iterator and a const_iterator?

Solution

Example of const_iterator:

Following is the example of the const_iterator.

vector<string>:: const_iterator it;

for (it = inventory.begin() ; it != inventory.end() ; ++it )

{

     cout<<*it<<endl;

}

Example of iterator:

Following is the example of the regular iterator.

vector<string>::iterator it;

for ( it = inventory.begin() ; it != inventory.end() ; ++it )

{

     cout<<*it<<endl;

}

Explain why we need both an iterator and a const_iterator?SolutionExample of const_iterator: Following is the example of the const_iterator. vector<string>

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site