The << operator of the ofstream class always convert numbers to printable characters. You can change the base for the number displayed using ios::dec, ios::hex, etc. I am sure you already looked into this and found that there is not ios::bin. This wouldn't help anyway since this only changes the base for the ASCII characters.
There are three ways to write true binary data.
1. use the cout.write() function as follows:
cout.write((char*)(&MyInt), sizeof(MyInt));
2. subclass ofstream and over-ride a method so that int types are no longer converted to characters. The hardest part of this approach is finding exactly what to over-ride. #3 May give you a hint to finding the right method to over-ride.
3. Create a class that overrides the << operator as follows:
ofstream& operator << (ofstream& out, Myclass& var){
}
The above method signiture should appear in the new class called Myclass. Then its up to you to write the de-conversion code. Something along the linesof accessing the integer using a char* and feeding to the regular cout<< a char at a time should work, because there is no conversion for characters.