Hey guys, just running into a small problem, and not sure if what I am attempting is possible, but I don't see why it wouldn't be. I am just delving into STL components and writing simple programs to try them out.
I have a program that needs to regularly print vectors, so I made a function to do so. It worked fine with a regular for loop (int i = o, etc), but I wanted to try it with an iterator.
The function:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void printVector(const vector <int> *inVector, const string inName)
{
vector<int>::iterator it;
cout << inName << " is size " << inVector->size() << " with a " << inVector->capacity() << " element capacity:\n";
for (it = inVector->begin(); it != inVector->end(); it++)
{
cout << *it << " ";
}
cout << "\n\n";
}
|
The call:
printVector(&vecOne, "vecOne");
The error:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type
'std::_Vector_const_iterator<_Ty,_Alloc>' (or there is no acceptable conversion) 109
|
I am just trying to set 'it' to the beginning of the vector, then move through to the end, printing each element. My error messages come from both '=' and '!=' operators within the for parameters. I feel like it should work, but my syntax is off since it is operating from a pointer to the vector, rather than the vector itself.
I am venturing outside of what I've been taught over school break, so I'm a bit over my head in a few instances. I am writing in Visual Studio 2008, if that matters. Any help on the problem or commentary on other aspects of the code is appreciated, thank you.