#include <iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
int a;
ofstream outfile("f2.dat",ios::out|ios::binary);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
cin>>a;
outfile.write((char*)&a,sizeof(int));
cout<<"The numbers have been writen to file."<<endl;
outfile.close();
return 0;
}
运行结果: