updating an array

I'm not sure if I'm phrasing this right...
I'm trying to read an array, copy info into
another array and then work with that new array.

For instance:
-do stuff with current array
-results go into new array
-new array becomes current array
-do stuff with current array

What are my options? And let me know if this isn't specific enough.
I'm not entirely sure this is what you mean, but if you are using std::vector, there's a swap() function which does what you're describing:

1
2
3
4
5
6
7
8
9
std::vector<int>  a(10);   // array of 10 elements
std::vector<int>  b(10);

// do stuff with 'a'
// results go in 'b'

a.swap(b);  // swap a and b

// now, 'a' is the old b and b is the old a 
Well I'm definitely not using vectors, but your idea about "swapping" is what I was talking about. I just have myarray[][] and newarray[][] and I need to make newarray become myarray.
Jagged arrays are the worst. Create a struct or a class that encompasses your related data, and then use a one-dimensional array of structs/objects. This would be a much preferred way, if your scenario allows for it.
multidimention arrays = YUK YUK YUK

If you are using pointers you can swap the pointers:

1
2
3
4
5
6
7
int* a = new int[10];
int* b = new int[10];

// swap a and b
int* tmp = a;
a = b;
b = tmp;


If you're using straight arrays, then the only way to swap them then is to copy all the data over.
Topic archived. No new replies allowed.