-4

hey i would like to know how you could cast an Int array in C++ to an byte array and what would be the declaration method. I would appreciate if it is simpler and no use of pointers. thanks for the comments

1 Answers1

1

This solution is a bit less convenient but maybe a bit more understandable from your perspective:

std::array<int, 3> arr_ints = {1, 2, 3};
std::array<unsigned char, 3> arr_bytes;

for(unsigned i=0; i<arr_ints.size(); ++i)
    arr_bytes[i] = static_cast<unsigned char>(arr_ints[i]);
informant09
  • 158
  • 15