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