p11_12.cpp
来自「相当丰富的C++源码」· C++ 代码 · 共 26 行
CPP
26 行
/****************************************************
* 程序名:p11_12.cpp *
* 功能: 二进制文件的输入 *
* By Antony *
* 02-08-2005 *
****************************************************/
# include <fstream>
# include <iostream>
using namespace std;
void main() {
char name[8];
float score;
ifstream binfile; //建立输入文件流对象
binfile.open("d:\\c++book\\record.dat",ios::binary);
if(!binfile) {
cerr<<" record.dat open error!"<<endl;
exit(1);
}
while(!binfile.eof()) {
binfile.read(reinterpret_cast<char *>(name),8*sizeof(char));
binfile.read(reinterpret_cast<char *>(&score),sizeof(float));
cout<<name<<'\t'<<score<<endl;
}
binfile.close();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?