Vector pop.back
Apr 2, 2013 at 10:40pm UTC
Hello People....
I got a vector that stores distances between two points, Now i iterate over this vector to retrieve the values stored in it that I will use for different calculations. But before I do that i want to makes sure that the vector does not store any values that are == 0 for memory management.
I have this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
double Pt3;
double Pt4;
for (vector<Point>::iterator iter_b = Right_Arm_xy.begin()+1; iter_b != Right_Arm_xy.end(); ++iter_b)
{
Pt3 = pow((double ) iter_b->x - (iter_b -1)->x,2);
Pt4 = pow((double ) iter_b->y - (iter_b -1)->y,2);
double result_b;
result_b = (Pt3 + Pt4);
Right_Point_distance.push_back(sqrt(result_b));
}
for (vector<double >::iterator iter_dist = Right_Point_distance.begin(); iter_dist != Right_Point_distance.end(); ++iter_dist)
{
if (*iter_dist == 0)
{
Right_Point_distance.pop_back();
}
}
I think the way I am trying to pop.back an element is not correct....could anybody suggest a solution to what i am trying to achieve. Regards
Apr 2, 2013 at 10:44pm UTC
1 2 3 4 5 6 7 8
for (vector<double >::iterator iter_dist = Right_Point_distance.begin(); iter_dist != Right_Point_distance.end(); /*nothing*/ )
{
if (*iter_dist == 0)
{
iter_dist = Right_Point_distance.erase(iter_dist);
}
else ++iter_dist;
}
Also I like that you use tabs and not spaces for indentation :) it's too bad the forum stretches out tabs like a maniac.
Last edited on Apr 2, 2013 at 10:44pm UTC
Topic archived. No new replies allowed.