标题:存储的fwrite()问题
取消只看楼主
yijing21
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-11-7
 问题点数:0 回复次数:1 
存储的fwrite()问题
struct student{                                        
    int num;
    string name;
    int score[3];
};
void Information::save_file()
{
    student stu;
    string name;
    FILE *stream;
    fopen("stu.dat","wb+");
    int score;
    int num;
    
    cout<<"请输入8位学号:";
    cin>>stu.num;

    cout<<"\n请输入名字:";
    cin>>stu.name;
    
    cout<<"\n请输入数学成绩";
    cin>>stu.score[0];
    cout<<"请输入英语成绩";
    cin>>stu.score[1];

    
    cout<<"请输入政治成绩";
    cin>>stu.score[2];
    
    fwrite(&stu,sizeof(struct student),1,stream);
    fclose(stream);
    
}

int main()
{
    Information IF;
    IF.save_file();
    return 0;
}


为什么程序在对其输入3门成绩后显示运行出错了  是不是fwrite()应用出问题了  顺便问一句  是不是C++中存储数据到文件一般用什么方法啊 ?   急等解答。。
搜索更多相关主题的帖子: fwrite 
2008-04-16 11:06
yijing21
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-11-7
得分:0 
哦。。。忘了  给stream初始化   多谢楼上提醒
2008-04-16 11:55



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




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

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