64,639
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
struct ppp
{
int i;
string str;
char c;
};
void read(ppp &b);
void write();
int main()
{
ppp b;
write();
read(b);
cout <<b.c <<b.i <<b.str <<endl;
return 0;
}
void write()
{
FILE *fp=fopen("e:\\c.txt","wb");
ppp a;
a.c='m';
a.i=20;
a.str="Smith";
fwrite(&a,sizeof(struct ppp),1,fp);
}
void read(ppp &b)
{
// ppp b;
FILE *fr=fopen("e:\\c.txt","rb");
fread(&b,sizeof(struct ppp),0,fr);
}
void write()
{
FILE *fp=fopen("c.txt","w");
ppp a;
a.c='m';
a.i=20;
a.str="Smith";
fwrite(&a,sizeof(struct ppp),1,fp);
fclose(fp);
}
void read(ppp &b)
{
// ppp b;
FILE *fr=fopen("c.txt","r");
fread(&b,sizeof(struct ppp),1,fr);
fclose(fr);
}