I am working on a project where I am placing an enum into a vector. and I was wondering how I could get functionality like such out of the vector.
for(int ii = 0; ii < thing.getSize(); ii++){
cout << "thing(" << ii << ") = " << toString(thing[ii]) << endl;
}
I’ve tried about 5 different ways to do this, and none of them seem to work. I have read through MSDN vector (vector::end() seemed the most helpful until it said that the operator<< wouldn’t accept ii as an iterator.
can somebody help me out? the closest I think I got was
vector<int>::iterator ii;
for(ii = things.begin(); ii != things.end(); ii++){ //764
cout << "thing(" << (int)ii << "): " << toString(things[ii]) << endl; //765
}
but this throws errors that either don’t make sense or I can’t figure out how to solve.
1>c:\...\Project.cpp(764): error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion)
1>c:\...\Project.cpp(765): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion)
1>c:\...\Project.cpp(765): error C2679: binary '[' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion)
thingshas to be declared as:You can enter your values into the vector like so:
Then you iterate like this: