How to copy an array from struct to another array?

2

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?

    
asked by anonymous 16.08.2018 / 02:38

1 answer

5

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);

Documentation .

Or you could use a C ++ function:

copy(begin(e1), end(e1), begin(e2));

Documentation .

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.

    
16.08.2018 / 02:46