How do I convert a std::vector<uint8_t>
to my custom defined structure?
For example I have
struct abc
{
char a;
char b;
char c;
};
Does reinterpret_cast
works in this?
I am a beginner in C++, but have good knowledge in C.
How do I convert a std::vector<uint8_t>
to my custom defined structure?
For example I have
struct abc
{
char a;
char b;
char c;
};
Does reinterpret_cast
works in this?
I am a beginner in C++, but have good knowledge in C.
You can't, at least not in a type safe and supported way. What you can do is roll your own copy method. In your case it would be as simple as memcpy(vec.data(), &struct, sizeof(struct))
assuming the vector is a direct translation (i.e 3 elements).