i have a class called block with 2 floats x and y.
i am iterating through a vector called 'block_array'
how do I get the x value of each object in the vector?
I am using this code to iterate:
for (std::vector<block>::iterator it = block_array.begin(); it!=block_array.end(); ++it) {
how do I print out each x value of each object in the vector?
Dereference it. It's just like a pointer.
i tried *it.x but it said iterator didnt have a member 'x'
the . operator works before the * operator does. You'd have to do either (*it).x
, or its equivalent. it->x
.