0

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

0

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.