永发信息网

请各位高手帮我看看这个程序段为什么不行,无法保存修改后的结果。

答案:1  悬赏:50  手机版
解决时间 2021-05-07 18:42
  • 提问者网友:夢醒日落
  • 2021-05-06 20:44

void message::alter()
{
    ifstream inData("pmessage.txt", ios::in);
   
    if (!inData)
    {
        cout <<endl <<"对不起不能打开文件!!!!!" <<endl <<endl;
        system("pause");
        return;
    }
   
    string sign;
    cout <<endl <<"请输入你想要修改的学生的姓名或学号:";
    cin >>sign;
    fflush(stdin);
   
    string str1;
    getline(inData, str1);
   
    memorize *H = new memorize;
    memorize *p = H;
    memorize *q = H;
    bool flag = true;
   
    while (inData >>p->object.name >>p->object.number >>p->object.qq
        >>p->object.major >>p->object.classnum)
    {
        p->next = new memorize;
        p = p->next;
        p->prior = q;
        q->next = p;
        q = p;
    }
    p->next = NULL;
   
    inData.close();
   
    p = H;
    while (p)
    {
        if ((p->object.name==sign) || (p->object.number==sign))
        {
            if (flag)
            {
                cout <<endl <<"你想修改你学生的信息如下: " <<endl <<endl;
                cout <<endl <<str1 <<endl;
                cout <<setiosflags(ios::left) <<setw(17)
                    <<p->object.name <<" " <<setw(16) <<p->object.number
                    <<" " <<setw(18) <<p->object.qq
                    <<" " <<setw(14) <<p->object.major
                    <<" " <<setw(20) <<p->object.classnum <<endl;
                flag = false;
            }
            cout <<endl <<"请根据下面提示修改信息 : " <<endl;
            cout <<"姓名  :" ;
            cin >>p->object.name;
            fflush(stdin);
            cout <<"学号  :";
            cin >>p->object.number;
            fflush(stdin);
            cout <<"班级   :";
            cin >>p->object.classnum;
            fflush(stdin);
            cout <<"QQ   :";
            cin >>p->object.qq;
            fflush(stdin);
            cout <<"专业  :";
            cin >>p->object.major;
            fflush(stdin);
            break;
        }
       
        p = p->next;
    }
   
    if (flag)
    {
        cout <<endl <<"你的花名册中没有你找的学生 !!!!" <<endl <<endl;
        system("pause");
        return;
    }
    else
    {
        ofstream out("pmessage.txt",ios::out);
       
        if (!out)
        {
            cout <<endl <<"对不起!!!不能打开文件!!!!" <<endl;
            system("pause");
            return;
        }
       
        out <<str1 <<endl;
        p = H->next;
        while (p)
        {
            cout <<setiosflags(ios::left) <<setw(17) <<p->object.name
                <<" " <<setw(16) <<p->object.number
                <<" " <<setw(18) <<p->object.qq
                <<" " <<setw(14) <<p->object.major
                <<" " <<setw(20) <<p->object.classnum <<endl;
            p = p->next;
        }
       
        out.close();
        cout <<endl <<"信息已经修改完成!!!!" <<endl <<endl;
        system("pause");
    }
}

//查询联系人
void message::select()
{
    ifstream inData("pmessage.txt",ios::in);
   
    if (!inData)
    {
        cout <<endl <<"对不起!!!!文件找不到!!!!" <<endl;
        system("pause");
        return;
    }
   
    string sign;
    cout <<endl <<"输入你想查找的学生的姓名或学号: ";
    cin >>sign;
    fflush(stdin);
   
    string str1;
    bool flag = true;
   
    string str;
    while (inData >>name >>number)
    {
        getline(inData, str);
       
        if ((name==sign) || (number==sign))
        {
            cout <<endl <<"你要查找的学生是: " <<endl <<endl;
            cout <<str1 <<endl;
            cout <<setiosflags(ios::left) <<setw(17) <<name
                <<number <<str <<endl;
            flag = false;
            break;
        }
    }
 system("pause");
}

最佳答案
  • 五星知识达人网友:玩世
  • 2021-05-06 21:55
你的问题好像是安装了绿化版才会出现的情况,需要找到软件图标,先打开软件,然后才能打开文件,不知道你的是不是绿化版的
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯