I want to use an std::array
of std::byte
to store a binary message.
#include <cstddef>
#include <array>
int main() {
std::byte b {42}; // OK
std::array<std::byte, 2> msg {42, 43}; // Compilation Error
}
I'm getting the following error:
<source>: In function 'int main()':
<source>:6:35: error: cannot convert 'int' to 'std::byte' in initialization
6 | std::array<std::byte, 2> msg {42, 43};
| ^~
| |
| int
Why I'm getting this error and how to fix it?