what I’m trying to do is append a binary integer into a string object. So far I have this:
int number = 5;
cppstring.append((char*)&number, 4);
It works fine on a x86 system with Windows, but some people are saying its not cross-platform and is unsafe. What is the preferred method to do this?
The reason it’s not portable is that ints are not always 4 bytes. For instance, the ILP64 data model uses 8-bytes ints. C99 only requires that ints are at least 2 bytes. Why do you need to do this, and what is the desired behavior if the size of the int is not 4 bytes?