updating struct size while keeping old data

Hey guys,

I have a problem and I would like to know how to solve it. I am having a struct where the struct takes 4 inputs. 3 of these inputs are arrays of size 2. The struct itself is of a variable size "newsize" as you can see. I am changing the value of "newsize" with a for loop but the problem if the size is updated the data from the previous step vanish because I am reinitializing the size of struct. Any help how to increase the size of the struct with each iteration while keeping the data from the previous iteration

struct coordinates

{
double x_coordinate[2];
double y_coordinate[2];
double z_coordinate[2];
double orient;
};
coordinates density[newsize];

Last edited on
Use a
vector<coordinates>
instead of an array. Make a coordinate object, push it onto the back of the vector with push_back. You don't have to worry about the size.
Sorry I have not used vectors before. do you mean inside of struct itself I have to use vectors instead of array
Last edited on
No.

1
2
3
vector<coordinates> vector_of_coordinates; // make a vector of coordinates

vector_of_coordinates.push_back(some_coordinates_object); // do this until you've made all the coordinate objects you're gong to make 


Last edited on
ok thanks man. One last question how do I save the result from previous iterations
You just added it to the vector. It's in there.
Thanks very much
Topic archived. No new replies allowed.