f.write((const char *)&v, 4);

ovvero

f.write(reinterpret_cast<const char *>(&v), 4);