求关于二进制文件的基本概念以及用法
老师布置了一个学生系统的编程任务,虽然已经把基本代码写出来了,可是关于文件保存(即程序实现时数据的保存)因为查不到资料无法前进,故想请一个高手帮忙,教我有关关于程序运行结束后如何将里面数据保存,下次运行时还能用到~学生系统代码如下,希望能得到帮助。。。。#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<stdlib.h>
#include<math.h>
#include<iomanip.h>
struct student
{
char num[10];
char name[15];
float english;
float math;
float computer;
};
student o[100];
void print(student pr)
{
cout<<pr.num<<setw(4)<<pr.name<<setw(4)<<pr.english<<setw(4)<<pr.math<<setw(4)<<
}
void remain()
{
cout<<"please follow the order input"<<endl;
cout<<"num"<<" "<<"name"<<" "<<"english"<<" "<<"math"<<" "<<"computer"<<endl;
}
void main ()
{
int n=0;
while(1)
{
zzh:printf("按1键对数据进行增加\n");
printf("按2键对数据进行删除\n");
printf("按3键对数据进行显示\n");
printf("按4键退出程序\n");
int x;
scanf("%d",&x);
if(x==1)
{
while(1)
{
printf("please input the information of the student\n");
printf("please input the number of the student you want add\n");
int a,i;
scanf("%d",&a);
for(i=n;i<a+n;i++)
{
remain();
cin >> o[i].num >> o[i].name >> o[i].english >> o[i].math >> o[i].computer;
}
n=a+n;
int z;
for(z=0; z<n; z++)
print(o[z]);
printf("press the 'q' and out the step of add\n");
char u;
scanf("%c",&u);
if(u=='q')
goto zzh; // 程序为什么要运行两次之后才能退出循环~
}
}
if(x==2)
{
lp:printf("please input the data you want cancel\n");
int j,l,p,r;
scanf("%d",&l);
scanf("%d",&p);
if(p>=n)
{
printf("the data wasn't enough,so please input again\n");
printf("press the 'q' and out the step of cancle.\n");
char u;
scanf("%c",&u);
if(u=='q')
goto zzh;
goto lp;
}
r=p+1;
for(j=l;j<n;j++) //对l~p的数据进行删除,用后面数据覆盖前面数据,改变n的值达到删除的目的。
{
o[j]=o[r]; //从0开始的新类型~ 理解错误~
r++;
}
n=n-p+l-1;
int q;
for(q=0;q<n;q++)
print(o[q]);
}
if(x==3)
{
while(1)
{
printf("what function do you want\n");
printf("press '1' will print all the date\n");
printf("press '2' will print the date alone\n");
printf("press '3' will print the date you want as fllows\n ");
printf("the date limit 0~%d\n",n);
int y;
scanf("%d",&y);
int d,v,e;
if(y==1)
{
for(d=0;d<n;d++)
print(o[d]);
}
if(y==2)
{
scanf("%d",d);
print(o[d]);
}
if(y==3)
{
scanf("%d",&e);
scanf("%d",&v);
for(d=e;d<=v;d++)
print(o[d]);
}
char t;
scanf("%c",&t);
if(t=='q')
break;
}
}
if(x==4)
break;
}
}