Reputation: 169
I have arrays of struct and I want to append them in a single array,
I have declared three arrays like below,
ec_pdo_entry_reg_t array1[2];
ec_pdo_entry_reg_t array2[2];
ec_pdo_entry_reg_t array3[4];
and want to make array3 is the combination of array1 and array2, how can I do this?
I have define array array1 and array2 with similar values,
array1[0].a = a;
array1[1].b = b;
array2[0].a = a;
array2[1].b = b;
I have just taken the fake value just to make my question understandable for you. kindly guide me how can append array1 and array2 in array3?
Thank you.
Best Regards Nabeel
Upvotes: 0
Views: 253
Reputation: 27567
Use std::copy
, something like:
#include <algorithm>
ec_pdo_entry_reg_t array1[size1];
ec_pdo_entry_reg_t array2[size2];
ec_pdo_entry_reg_t array3[size1 + size2];
// ...
std::copy(array1, array1 + size1, array3)
std::copy(array2, array2 + size2, array3 + size1)
Upvotes: 3