本文共 1208 字,大约阅读时间需要 4 分钟。
对比ASCII文件和二进制文件
//将short int x=12345写入文本文件#include#include #include using namespace std;int main( ){ short int x=12345; ofstream outfile("binary.dat"); if(!outfile) { cerr<<"open error!"<
//将short int x=12345写入二进制文件#include将数据以二进制形式存放在磁盘文件中#include #include using namespace std;int main( ){ short int x=12345; ofstream outfile("binary.dat",ios::binary); if(!outfile) { cerr<<"open error!"<
#include将二进制文件中的数据读入内存#include #include using namespace std;struct student{ char name[5]; int num; int age; char sex;};int main( ){ student stud[3]= { {"Li",25,18,'f'}, {"Fun",32,19,'m'}, {"Wang",40,17,'f'} }; ofstream outfile("stud.dat",ios::binary); if(!outfile) { cerr<<"open error!"<
#include#include #include using namespace std;struct student{ char name[5]; int num; int age; char sex;};int main( ){ student stud[3]; int i; ifstream infile("stud.dat",ios::binary); if(!infile) { cerr<<"open error!"<
转载地址:http://ocgma.baihongyu.com/