第16周-课堂习题-体验二进制文件

来源:互联网 发布:centos 6.6网卡配置 编辑:程序博客网 时间:2024/05/22 04:23
#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;}


运行结果:


0 0
原创粉丝点击