C++二进制文件的读写

来源:互联网 发布:远光软件北京分公司 编辑:程序博客网 时间:2024/05/17 03:08
#include <iostream>
#include <cstdio>
#include <fstream>
#include <cstring>
using namespace std;
class CStudent{
public:
char szName[20];
int nSore;
};
int main()
{
CStudent s;
ofstream OutFile("D:\\student.dat",ios::out|ios::binary);
while(cin>>s.szName>>s.nScore)
{
if(stricmp(s.szName,"exit")==0)
break;
OutFile.write((char *)&s,sizeof(s));
}
OutFile.close();
return 0;
}

0 0
原创粉丝点击