共有两组,将不同组的学生划分到同一组

img


共有理工科与人文经管两组,怎样将这两组的学生划分到自己的组中。希望各位详细解答,谢谢。

是要修改分组吗?字符串需要用双引号括起来啊。 == “理工科”
代码修改如下:

struct student
{
    string jiaoshougognhao;
    string xingming;
    string zhicheng;
    string xueyuan;
    string zubie;
};


void studentbaoming()
{
    student s;
    cout << "报名" << endl;
    cout << "请输入基本信息:" << endl;
    cout << "教师工号:";
    cin >> s.jiaoshougognhao;
    cout << "姓名:";
    cin >> s.xingming;
    cout << "职称:";
    cin >> s.zhicheng;
    cout << "学院:";
    cin >> s.xueyuan;
    cout << "组别:";
    cin >> s.zubie;

    if (s.zubie.compare("理工科") == 0)
    {
        ofstream ofs("理工科选手信息.txt", ios::app);
        ofs << i + 1 << "." << s.jiaoshougognhao << " " << s.xingming << " " << s.zhicheng << " " << s.xueyuan << " " << s.zubie << endl;
        ofs.close();
    }
    else
    {
        ofstream ofs("人文经管科选手信息.txt", ios::app);
        ofs << i + 1 << "." << s.jiaoshougognhao << " " << s.xingming << " " << s.zhicheng << " " << s.xueyuan << " " << s.zubie << endl;
        ofs.close();
    }

    i++;

}

你这代码有好几个问题
1.字符串要括起来,否则理工科是个变量
2.字符串不能用等和不等来比较,那比较的是指针地址,应该用strcmp

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632