标题:为什么总显示文件打开错误
取消只看楼主
zknever
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-5-3
结帖率:100%
 问题点数:0 回复次数:0 
为什么总显示文件打开错误
#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;
}
2011-05-17 21:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-340214-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.096401 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved