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日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。