为什么总显示文件打开错误
#include<iostream>#include<fstream>
#include<string>
using namespace std;
void append()
{
int add;
fstream outfileNumber("number.txt",ios::app) ;
fstream outfileName("name.txt",ios::app);
fstream outfileSex("sex.txt",ios::app);
fstream outfileAge("age.txt",ios::in);
fstream studentNumber("studentNumber.tex",ios::in);
if((!outfileNumber)||(!outfileName)||(!outfileSex)||(!outfileAge))
{
cout <<"文件打开错误!"<<endl;
exit(1);
}
cout <<"输入添加学生个数:";
cin >>add;
studentNumber <<add;
class student
{
public:
long int num;
string name;
char sex;
int age;
};
student *stu=new student [add];
for(int i=0;i<add;i++)
{
cout <<"输入学号:";
cin >>stu[i].num;
outfileNumber <<stu[i].num;
cout <<"输入姓名:";
getline (cin,stu[i].name);
outfileName <<stu[i].name;
cout <<"输入性别:";
cin >>stu[i].sex;
outfileSex <<stu[i].sex;
cout <<"输入年龄:";
cin >>stu[i].age;
outfileAge <<stu[i].age;
}
outfileNumber.close();
outfileName.close();
outfileSex.close();
outfileAge.close();
studentNumber.close();
}
int main()
{
append();
return 0;
}