I have 2 arrays made from a struct
:
struct events {
string Kind;
int Time;
int DurVal;
int Chan;
};
events e1[100]
events e2[100];
How can I make a full copy of array e1
to e2
in a simple command?
I have 2 arrays made from a struct
:
struct events {
string Kind;
int Time;
int DurVal;
int Chan;
};
events e1[100]
events e2[100];
How can I make a full copy of array e1
to e2
in a simple command?
Since you are using code that you should only use in C instead of C ++, you could use a C:
memcpy(e1, e2, sizeof(events) * 100);
Or you could use a C ++ function:
copy(begin(e1), end(e1), begin(e2));
Or at hand:
for (auto i = 0; i < 100; i++) e2[i] = e1[i];
But I would use a vector
or array
which is more the face of C ++ and is more secure and faster in many cases.