-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

3

1 Answer 1

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

2 Comments

0 | arr_ints[i]does not make much sense, does it? Is it intended to suppress a cast warning? Then a real cast would be much better.
Changed it to an explicit cast!