Is it possible to iterate over a const vector<int>
? Or, would this be undesirable anyway?
Given I have the function getIntVector
which returns a vector<int>
I can iterate over it with the following:
vector<int> vec = getIntVector();
vector<int>::iterator it;
for (it=vec.begin();it!=vec.end();++it) {}
But I can not do the following:
const vector<int> vec = getIntVector();
vector<int>::iterator it;
// complier throws error below
for (it=vec.begin();it!=vec.end();++it) {}
My thinking was that the vector would not be recreated by declaring it as a const
....