文件读取和输出有关问题
#include<iostream>#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("f5.txt",ios::binary);
if(!outfile)
{
cerr<<"open error!"<<endl;
abort();
}
for (int i=0;i<3;i++)
outfile.write((char*)&stud[i],sizeof(stud[i]));
outfile.close();
return 0;
}
为什么不能在指定的TXT文件内得到三个相应的结构体元素的内容,,输出是乱码!