There are many different ways, but if you tell us what exactly "doesn't work" we could help you fix this one.

int n=800;
ofstream out;
out.open( "filename", ios::binary );
if( out.fail() ) // do something, file not opened
out.write( &n, sizeof( n ) );
out.close();


http://www.cplusplus.com/ref/iostrea...eam/write.html