1、写
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct But
{
int Num;
char name[10];
double high;
short age;
};
int main()
{
struct But b = { 123,"mw",180,22 };
FILE* pFile = fopen("C:\\Users\\lucky\\Desktop\\22.txt", "w");
fwrite(&b, sizeof(b), 1, pFile);
fclose(pFile);
system("pause");
return 0;
}
2、读
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct But
{
int Num;
char name[10];
double high;
short age;
};
int main()
{
struct But b = { 123,"mw",180,22 };
struct But c;
FILE* pFile = fopen("C:\\Users\\lucky\\Desktop\\22.txt", "r");
fread(&c, sizeof(c), 1, pFile);
fclose(pFile);
system("pause");
return 0;
}