int x = 5;
cout<<(char)x;
the code above outputs an int x in raw binary, but only 1 byte. what I need it to do is output the x as 4-bytes in binary, because in my code, x can be anywhere between 0 and 2^32-1, since
cout<<(int)x;
doesn’t do the trick, how would I do it?
You can use the
std::ostream::write()member function:Note that you would usually want to do this with a stream that has been opened in binary mode.