|
|
vector<Position> cp;vector<Position> cp gets values, such as i and j which are some coordinates. Then as the iteration goes on i and j get new values. What we needed is that the values of i and j be deleted before the new vales come, so that vector<Position> cp becomes an empty vector. cp.clear(); cp.erase(cp.begin(),cp.begin()+2);cp.clear() would clear all of the Position objects out of the vector, not the position object's data members i and j.cp.clear() will work fine, as shown in this sample program below: |
|
Before Clear: 1, 2, 3, 4, 5, After Clear: |
cp.erase(std::begin(cp), std::end(cp));cp.clear() is not working, it's more likely that your program is repopulating the vector erroneously, or there is some other logic error. If you supply contextual code to your question, I may be able to help more.
|
|
i and j values or as you mentioned the data members of the position objects in the vector. So, is there a way to do this? Otherwise, I have tried cp.clear(); and cp.erase(cp.begin(),cp.begin()+2); and that does not work as expected.cp.erase(std::begin(cp), std::end(cp)); but it did not work.cp.pop_back(); did not do what I want. It reacts as cp.clear(); . i and j values or the data members of the position objects in a vector consisting of e.g. structures we should iterate over each position object and call a clear method on each one. Below the key components of the code are presented : |
|
vector<Position> cp; |
|
i and j by making them to be 0. However, this does not make vector<Position> cp; an empty vector.cp.clear(); . And this makes vector<Position> cp; an empty vector. i and j values or the data members of the position objects in a vector and to transform the vector<Position> cp; into an empty vector we can use the two, one after another, which I did.
|
|
|
|
cp.clear() // Clears the vector of all of the position objects cp.clear(); ) got in to the struct Position . Actually I did not used it in my original code. It happens sometimes. I mean I have noticed that recently my computer reacts in a strange manner, it copies and pastes things I do not have any clue. I think the problem is connected with the touch pad. vector<Position> cp; like some object integrated into some other. Thanks for the help.