谢谢各位
#include<iostream>
#include<fstream>
using namespace std;
struct student
{
char name;
int num;
int age;
char sex;
};
int main()
{student stud[3]={"li",1001,14,'f',"Fun",1002,19,'m',"wang",1003,21,'f'};
ofstream outfile("d:\\stud.txt",ios::binary);
if(!outfile)
{
ceer<<"open error!"<<endl;
abort();
}
for(int i=0;i<3;i++)
outfile.write((char *)&stud[i],sizeof(stud[i]));
outfile.close();
return 0;
}
上述程序没错!但当我打开stud.txt文件时为什么里面的数据都乱了跪求高手指导,谢谢