resizing an array to the size of another array
-
I need to copy an array, but I don't know the size until after the program has parsed a file. I created a pointer to the new array like this:
double *data_ptr = new double[];
I then have a counter that counts as the file is parsed. I call this counter int num_signals; Once the file is parsed I nee dto resize the array with the size of num_signals.double *data_ptr = new double[num_signals];
How can I do this? thanks, sj:) -
I need to copy an array, but I don't know the size until after the program has parsed a file. I created a pointer to the new array like this:
double *data_ptr = new double[];
I then have a counter that counts as the file is parsed. I call this counter int num_signals; Once the file is parsed I nee dto resize the array with the size of num_signals.double *data_ptr = new double[num_signals];
How can I do this? thanks, sj:)Why not use an stl class like vector? vector will handle all the details of this for you. John
-
I need to copy an array, but I don't know the size until after the program has parsed a file. I created a pointer to the new array like this:
double *data_ptr = new double[];
I then have a counter that counts as the file is parsed. I call this counter int num_signals; Once the file is parsed I nee dto resize the array with the size of num_signals.double *data_ptr = new double[num_signals];
How can I do this? thanks, sj:)Unless you are using
data_ptr
during the parsing of the file, don't initialize it until afterwards.