C程序设计文件流.pptVIP

  • 0
  • 0
  • 约6.29千字
  • 约 45页
  • 2020-07-26 发布于天津
  • 举报
32 【例 3.11_5 】将 3.11_4 以二进制形式存放在 磁盘文件中的数据读入内存并在显示器上显 示。 椣据畬敤尠獦牴慥?屨 struct student { char name[20]; int num; int age; char sex; }; int main( ) { student stud[3]; int i; ifstream infile(stud.dat,ios::binary); 33 if(!infile) { coutopen error!endl; return(0); } for(i=0;i3;i++) infile.read((char*)stud[i],sizeof(stud[i])); infile.close( ); for(i=0;i3;i++) { coutNO.i+1endl; cout ame:stud[i].nameendl; cout um:stud[i].numendl;; coutage:stud[i].ageendl; coutsex:stud[i].sexendlendl; } return 0; } 34 ? 问题:如果只想读出第 2 个学生的信息, 如何修改程序? 1 教学提纲 ? 一、教学内容: – 文件流操作 ? 二、学时:两课时 ? 三、教学目的和要求 – 掌握文件和文件流的概念 – 掌握文件打开、关闭和读

文档评论(0)

1亿VIP精品文档

相关文档