结构体输出的磁盘文件
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
struct abc
{ string name;
string number;
float average;
struct abc *next;
};
int main()
{
abc *head=new abc,*p,*q;
ofstream outfile("d:\\12.dat");
p=new abc;
head->next=p;
do
{
q=p;
cout<<"输入学生姓名:"<<endl;
cin>> p->name;
cout<<"输入学生学号:"<<endl;
cin>> p->number;
cout<<"输入平均分:"<<endl;
cin>> p->average;
p=new abc;
q->next=p;
p->next=NULL;
}while(q->average!=0);
p=head->next;
do
{
outfile.write((char*)p,sizeof(*p)); //怎么写才能把p所指向的结构体内容输出到文件中 ,我的是错误。
cout<<p->name<<setw(10)<<p->number<<setw(10)<<p->average<<endl;
p=p->next;
}while(p->next!=NULL);
system("pause");
return 0;
}