Ebenezer <woodbrian77@gmail.com> writes:
This change is now available on line and most of the
on line examples have been updated as well.
Very good thanks, but I still have a question.
What's the right way to convert generic types to a
std::vector<unsigned char>?
I mean should I maybe
- compute the size
- allocate the right space on the vector considering that every element
is just one byte
- memcpy (should be contigous the memory)
Or is there another way?
If for example I want to serialize a
vector<long> -> vector<char>
vector<char> convert(vector<long>& l)
{
vector<char> res;
size_t size = sizeof(long) * l.size();
res.resize(size);
memcpy(&res, &l, size);
return res;
}
Or am I getting into troubles with something like this??
Looks like that using memcpy with vectors is not really nice...