找回密码
 立即注册
搜索
查看: 1804|回复: 2

C++超级新手继续求问…

[复制链接]
发表于 2009-3-6 08:40 | 显示全部楼层 |阅读模式
厄…我是想在同一个TXT里输入东西的…

但是在不同的function 里对这个TXT写入东西就覆盖了原来的文件了…咋办捏?

这个是程序里的一小部分…
void TopMark(float mark[],int num_stud){
    ofstream fout;
    fout.open("topmarks.txt");
    int m=0;//top mark position
    int j;
    for(j=0;j<num_stud;j++){
        if(mark[j]>=mark[m])//get the top mark position in the mark[]
            m=j;
    }
    cout<<name[m]<<" gets the top mark "<<mark[m]<<endl;
    fout<<name[m]<<" gets the top mark "<<mark[m]<<endl;
    fout.close();
}

void BottomMark(float mark[],int num_stud){
    ofstream fout;
    fout.open("topmarks.txt");
    int m=0;
    int j;
    for(j=0;j<num_stud;j++){
        if(mark[j]<=mark[m])//get the lowest mark position in the mark[]
            m=j;
    }
    cout<<name[m]<<" gets the bottom mark "<<mark[m]<<endl;
    fout<<name[m]<<" gets the bottom mark "<<mark[m]<<endl;
}
   
int main(){
    int num_stud=50;//
   
    readmarks(num_stud);
    TopMark(mark,num_stud);
    BottomMark(mark,num_stud);
   
    return 0;

}

这样一来最后他就用BOTTOM MARK 的数据覆盖了我写入的TOP MARK的数据了…

求解…
回复

使用道具 举报

头像被屏蔽
     
发表于 2009-3-6 08:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 2009-3-6 08:56 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|上海互联网违法和不良信息举报中心|网上有害信息举报专区|962110 反电信诈骗|举报电话 021-62035905|Stage1st ( 沪ICP备13020230号-1|沪公网安备 31010702007642号 )

GMT+8, 2025-9-20 15:28 , Processed in 0.030245 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表