/*
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年6月18日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
#include<cstdlib>
using namespace std;
int main()
{
short int x=12345;
ofstream outfile("binary.dat);
outfile<<x<<endl;
outfile.close();
return 0;
}
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
short int x=12345;
ofstream outfile("binary.dat",ios::binary);
outfile.write((char*)&x,2);
outfile.close();
return 0;
}
*copvriqht(c)2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈传祯
*完成日期:2016年6月18日
*版本号:v1.0
*
*问题描述
*输入描述
*程序输出
*/
#include<iostream>
#include<fstream>#include<cstdlib>
using namespace std;
int main()
{
short int x=12345;
ofstream outfile("binary.dat);
outfile<<x<<endl;
outfile.close();
return 0;
}
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
short int x=12345;
ofstream outfile("binary.dat",ios::binary);
outfile.write((char*)&x,2);
outfile.close();
return 0;
}
本文提供了一个使用C++进行二进制文件写入操作的简单示例。示例通过ofstream类实现对short int类型变量的写入,并展示了两种不同的写入方式:一种是以普通文本方式写入;另一种则是以二进制形式直接写入变量的内容。

2993

被折叠的 条评论
为什么被折叠?



