m0_65112842 2022-06-18 22:48 采纳率: 93.8%
浏览 22
已结题

C++容器输出不显示是为什么

查重代码运行总是出现这个弹窗,该怎么解决?

img

用容器输入数据之后,输出不显示是为什么?

class Admin:public User
{
public:
    std::vector<Reference>str;
    Reference tmp;
    void input()//录入数据
    {
        cout << "请输入要录入的文献数\n";
        int n;
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cout << "请输入第" << i+1 << "篇文献的数据"<<endl;
            cin >> tmp.DOI >> tmp.author >> tmp.topic >> tmp.pub >> tmp.year >> tmp.type;
            str.push_back(tmp);
        }
        /*for (vector<Reference>::iterator it = str.begin(); it != str.end(); it++)
        {
            if ((*it).DOI == (*(it-1)).DOI)
            {
                cout << "录入数据有误,请重新录入"<<endl;
            }
        }//查重*/
    }
    void save()//保存数据
    {
        ofstream outFile;
        outFile.open("article.txt");
        for (vector<Reference>::iterator it = str.begin(); it != str.end(); it++)
        {
            outFile << (* it).DOI << (*it).author << (*it).pub << (*it).topic << (*it).year << (*it).type;
        }
        outFile.close();
        cout << "保存成功"<<endl;
    }
    void open()
    {
        char a[1000];
        ifstream fin;
        fin.open("article.txt");
        system("chcp 65001");
        fin >> a;
        cout << a;
    }
    void display()
    {
        for (vector<Reference>::iterator it = str.begin(); it != str.end(); it++)
        {
            cout << (*it).DOI << (*it).author << (*it).pub << (*it).topic << (*it).year << (*it).type << endl;
        }
    }
};

  • 写回答

1条回答 默认 最新

  • 浪客 2022-06-19 11:28
    关注
    
    void input() //录入数据
        {
            cout << "请输入要录入的文献数\n";
            int n, ishave;
            cin >> n;
            for (int i = 0; i < n; i++)
            {
                ishave = 0;
                cout << "请输入第" << i + 1 << "篇文献的数据" << endl;
                cin >> tmp.DOI >> tmp.author >> tmp.topic >> tmp.pub >> tmp.year >> tmp.type;
    
                for (vector<Reference>::iterator it = str.begin(); it != str.end(); it++)
                {
                    if ((*it).DOI == tmp.DOI)
                    {
                        cout << "录入数据有误,请重新录入" << endl;
                        ishave = 1;
                        break;
                    }
                } //查重*/
                if (ishave)
                {
                    i--;
                    continue;
                }
                str.push_back(tmp);
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月22日
  • 已采纳回答 9月14日
  • 创建了问题 6月18日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效