⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p11_10.cpp

📁 相当丰富的C++源码
💻 CPP
字号:
/***************************************************
* 程序名:p11_10.cpp                                *
* 功能: 二进制文件与文本文件比较                   *
*                    By Antony                      *
*                     02-08-2005                    *
****************************************************/
# include <fstream>
# include <iostream>
using namespace std;
void main() {
	char *name[3]={"Antony","John","Tom"};
	float score[3]={85.5, 90, 60};
	fstream txtfile,binfile;    //建立文件流对象
	txtfile.open("d:\\c++book\\record.txt",ios::out|ios::trunc);
    binfile.open("d:\\c++book\\record.dat",ios::binary|ios::out|ios::trunc);
	if(!txtfile) {
		cerr<<" record.txt open or create error!"<<endl;
		exit(1);
	}
	if(!binfile) {
		cerr<<" record.dat open or create error!"<<endl;
		exit(1);
	}
	for(int i=0;i<3;i++) {
		txtfile<<name[i]<<'\t'<<score[i]<<endl;
		binfile.write(name[i],8*sizeof(char));
		binfile.write((char *)&score[i],sizeof(float));
	}
	txtfile.close();
	binfile.close();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -