程序运行tushuinput、tushuDelete和tushuModify三个函数是出错,说明文件读写出现问题,请大虾们帮忙看看,谢啦
PS:附件中有CPP程序·内容如下:
#include<iostream>
#include<string>
#include<fstream>
#define N 100
using namespace std;
FILE *fp1;
struct Duzhe{
    string name;
    long num;
}c[N];
struct TuShu{
    int Num;    
    string name;    
    string author;
    Duzhe duzhe;
}a[N];
struct Guanli{
    long num;
    string name;
}b[N];
int n,k,d,m;


void shuinput()                                        //函数:添加图书信息
{    
    fp1=fopen("tushuguan.txt","a+");
    cout<<"输入要添加的图书书号,输入-1退出"<<endl;
    while(cin>>a[n].Num)
    {
        if(a[n].Num==-1)         
            break;
        cout<<"输入书名"<<endl;
        cin>>a[n].name;
        cout<<"输入作者名 "<<endl;
        cin>>a[n].author;
        char Seq[10];
        sprintf(Seq,"%d",a[n].Num);
        string Seq1(Seq);
        string blank1(10-Seq1.size(),' ');
        string blank2(15-sizeof(a[n].name),' ');    
        string tmp=Seq+blank1+a[n].name+blank2+a[n].author;    
        char *tmp1=const_cast<char*>(tmp.c_str());
    /*    char exa[30];int i=0;
        for(;i<tmp.size();i++)    
            exa[i]=tmp[i];
        exa[i+1]='\n';*/
        fputs(tmp1,fp1);    
        fputs("\n",fp1);
        n++;
    }
    fclose(fp1);
}
void shuFind()                                     //函数:查找图书信息
{    
    string str;
    int choose ,t,i;
    cout<<"-1.退出"<<"1.按书名查询"<<endl;    cout<<"2.按作者名查询"<<endl;
    cin>>choose;
    t=-1;    
    if(choose==1)
    {        
        cout<<"请输入书名:"<<endl;    
        cin>>str;        
        for(i=0;i<n;i++)
        {            
            if(str==a[i].name) 
            {
                t=i;
                break;
            }        
        }    
    }    
    if(choose==2)    
    {        
        cout<<"请输入作者:"<<endl;
        cin>>str;    
        for(i=0;i<n;i++)
        {        
            if(str==a[i].author) 
            {
                t=i;break;
            }        
        }    
    }    
    if(t==-1) 
        cout<<"找不到该信息,或输入有误"<<endl;
    else
    {        
        cout<<"书号:"<<a[i].Num<<" "<<"书名:"<<a[i].name<<" "<<"作者名:"<<a[i].author<<endl;
    }
}
void  shuDelete()
{    
    int i;    
    cout<<"请输入要删除书号:"<<endl;
    int key;    cin>>key;
    int t=-1;
    for(i=0;i<n;i++) 
        if(a[i].Num ==key) 
        {
            t=i;
            break;
        }    
        if(t==-1)
            return ;
        for(i=t;i<n-1;i++)
            a[i]=a[i+1];
        fp1=fopen("tushufile.txt","w");
        for(i=0;i<n-1;i++)
        {
            char Seq[10];
            sprintf(Seq,"%d",a[n].Num);
            string Seq1(Seq);
            string blank1(10-Seq1.size(),' ');
            string blank2(15-sizeof(a[i].name),' ');
            string tmp=Seq+blank1+a[i].name+blank2+a[i].author;
            char *tmp1=const_cast<char*>(tmp.c_str());
            fputs(tmp1,fp1);
            fputs("\n",fp1);        
        }
        n--;
        fclose(fp1);
}
void shuModify()
{    
    int i;
    cout<<"请输入要修改的图书书号:"<<endl;
    int  key;    
    cin>>key;
    int t=-1;
    for(i=0;i<n;i++) 
    {
        if(a[i].Num ==key)
        {
            t=i;
            break;
        }    
        if(t==-1)
            return ;    
    }
    cout<<"请输入修改的信息"<<endl;    
    cout<<"书号"<<endl;
    cin>>a[t].Num;
    cout<<"书名"<<endl;
    cin>>a[t].name;
    cout<<"作者名"<<endl;
    cin>>a[t].author;
    fp1=fopen("tushufile.txt","w");
    for(i=0;i<n-1;i++)
    {
        char Seq[10];
        sprintf(Seq,"%d",a[n].Num);
        string Seq1(Seq);
        string blank1(10-Seq1.size(),' ');
        string blank2(15-sizeof(a[i].name),' ');
        string tmp=Seq+blank1+a[i].name+blank2+a[i].author;
        char *tmp1=const_cast<char*>(tmp.c_str());
        fputs(tmp1,fp1);
        fputs("\n",fp1);        
    }
    fclose(fp1);
}

void readerinsert()
{
    cout<<"输入读者信息,输入-1退出"<<endl;    cout<<"读者卡号"<<endl;
    while(cin>>c[k].num)    
    {        
        if(c[k].num==-1) 
            break;    
        cout<<"读者名"<<endl;
        cin>>c[k].name;

    }
}
void readerdel()
{
    int i;    
    cout<<"请输入要删除读者姓名:"<<endl;
    string key;    cin>>key;
    int t=-1;
    for(i=0;i<k;i++) 
        if(c[i].name ==key) 
        {
            t=i;
            break;
        }    
        if(t==-1)
            return ;
        for(i=t;i<k-1;i++)    
            c[i]=c[i+1];
        k--;
}
void readermodify()
{
    int i;
    cout<<"请输入要删除读者姓名:"<<endl;
    string key;    
    cin>>key;
    int t=-1;
    for(i=0;i<k;i++) 
        if(c[i].name ==key)
        {
            t=i;
            break;
        }    
        if(t==-1)
            return ;    
        cout<<"请输入修改的信息"<<endl;    
        cout<<"读者名"<<endl;
        cin>>c[k].name;
        cout<<"读者卡号"<<endl;
        cin>>c[k].num;
}

void lend()
{
    string tmp;
    cout<<"请输入借阅图书信息:"<<endl;
    cin>>tmp;
    for(int i=0;i<n;i++)
    {
        while(a[i].name==tmp)
        {
            cout<<"请输入借书人的信息:"<<endl;
            cout<<"读者名"<<endl;
            cin>>a[i].duzhe.name;
            cout<<"读者卡号"<<endl;
            cin>>a[i].duzhe.num;
            break;
        }
    }
}
void revert()
{
    string tmp;
    cout<<"请输入归还图书信息:"<<endl;
    cin>>tmp;
    for(int i=0;i<n;i++)
    {
        while(a[i].name==tmp)
        {
            a[i].duzhe.name=" ";
            a[i].duzhe.num=-1;
            break;
        }
    }
}


void adiinsert()
{
    cout<<"输入管理员信息,输入-1退出"<<endl;        cout<<"管理员账号"<<endl;
    while(cin>>b[m].num)    
    {        
        if(b[m].num==-1) 
            break;    
        cout<<"管理员名"<<endl;
        cin>>b[m].name;
    }
}
void adidel()
{
    int i;    
    cout<<"请输入要删除管理员姓名:"<<endl;
    string key;    cin>>key;
    int t=-1;
    for(i=0;i<m;i++) 
        if(b[i].name ==key) 
        {
            t=i;
            break;
        }    
        if(t==-1)
            return ;
        for(i=t;i<m-1;i++)    
            b[i]=b[i+1];
        m--;
}
void adimodify()
{
    int i;
    cout<<"请输入要删除管理员姓名:"<<endl;
    string key;    
    cin>>key;
    int t=-1;
    for(i=0;i<n;i++) 
        if(a[i].name ==key)
        {
            t=i;
            break;
        }    
        if(t==-1)
            return ;    
        cout<<"请输入修改的信息"<<endl;    
        cout<<"管理员名"<<endl;
        cin>>b[m].name;
        cout<<"管理员账号"<<endl;
        cin>>b[m].num;
}
int main()
{
    int ops1;
    char ops2;
    n=m=k=d=0;
    fp1=fopen("tushufile.txt","w");
    do
    {
        cout<<"     \t\t欢迎进入图书管理系统    "<<endl;
        cout<<"\t1:图书管理"<<endl;
        cout<<"\t2:借阅管理"<<endl;
        cout<<"\t3:读者管理"<<endl;
        cout<<"\t4:馆员管理"<<endl;
        cin>>ops1;
        if(ops1==1)
        {
            cout<<"\t\t a.增加图书"<<endl;
            cout<<"\t\t b.修改图书"<<endl;
            cout<<"\t\t c.删除图书"<<endl;
            cout<<"\t\t d.统计图书"<<endl;
            cin>>ops2;
            switch(ops2)
            {
            case 'a':
                shuinput();cout<<n<<endl;break;
            case 'b':
                shuModify();break;
            case 'c':
                shuDelete();break;
            case 'd':
                cout<<"书库图书总数为:"<<n<<endl;break;
            default:
                break;        
            }
        }
        else if(ops1==2)
        {
            
            cout<<"\t\t a.查找图书"<<endl;
            cout<<"\t\t b.借阅图书"<<endl;
            cout<<"\t\t c.归还图书"<<endl;
            cout<<"\t\t d.借阅图书统计"<<endl;
            cin>>ops2;
            switch(ops2)
            {
            case 'a':
                shuFind();break;
            case 'b':
                lend();d++;break;
            case 'c':
                revert();d--;break;
            case 'd':
                cout<<"借出图书总数为:"<< d<<endl;break;
            
            default:
                break;        
            }
        }
        else if(ops1==3)
        {                
            cout<<"\t\t a.申请读者卡"<<endl;
            cout<<"\t\t b.删除读者卡"<<endl;
            cout<<"\t\t c.修改读者卡"<<endl;
            cin>>ops2;
            switch(ops2)
            {
            case 'a':
                readerinsert();k++;break;
            case 'b':
                readerdel();break;
            case 'c':
                readermodify();break;
            
            default:
                break;
            }
        }
        else if(ops1==4)
        {
            cout<<"\t\t a.添加管理员"<<endl;
            cout<<"\t\t b.删除管理员"<<endl;
            cout<<"\t\t c.修改管理员信息"<<endl;
            cin>>ops2;
            switch(ops2)
            {
            case 'a':
                adiinsert();m++;break;
            
            case 'b':
                adidel();break;
            
            case 'c':
                adimodify();break;
            
            default:
                break;
            }
        }
        else
            printf("选择错误 \n按任意键继续…\n");
    }while(1);    
    return 0;
}