#include <fstream>
int main() {
std::ofstream ofs("numtest.dat");
constint a { 7592 };
ofs.write((char*)&a, sizeof(a));
}
However whether this saves the data as 0xa81d0000 or 0x00001da8 depends upon byte ordering and whether binary data is stored as little-endian or big-endian.
It's not usually necessary to test your machine's byte order, because it's usually possible to write code in a way that lets the compiler take care of the differences.
It always puts the four bytes of n into the buffer pointed to by p in little-endian byte order. There's also extract_u32_le that takes n back out again.
The interface of these functions are supposed to work best in cases where formatting and writing (or reading and parsing) are separate operations. But if you don't care about that, you can just modify the code: