c13-14-2.cpp

来自「谭浩强C程序设计习题答案」· C++ 代码 · 共 23 行

CPP
23
字号
#include <fstream>
using namespace std;
struct student
{char name[20];
 int num;
 int age;
 char sex;
};
int main()
{student stud[3]={"Li",1001,18,'f',"Fun",1002,19,'m',"Wang",1004,17,'f'};
 ofstream outfile("stud.dat",ios::binary);
 if(!outfile)
  {cerr<<"open error!"<<endl;
   abort();
  }
  outfile.write((char *)&stud[0],sizeof(stud));
  outfile.close();
  return 0;
}



⌨️ 快捷键说明

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