You have to store the number of bytes in a separate (unsigned integer) variable. Neither C nor C++ have run-time sizeof.
If you have a buffer which can be of a fixed size, you can use a static ...