C++超级新手继续求问…
厄…我是想在同一个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>=mark)//get the top mark position in the mark[]
m=j;
}
cout<<name<<" gets the top mark "<<mark<<endl;
fout<<name<<" gets the top mark "<<mark<<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<=mark)//get the lowest mark position in the mark[]
m=j;
}
cout<<name<<" gets the bottom mark "<<mark<<endl;
fout<<name<<" gets the bottom mark "<<mark<<endl;
}
int main(){
int num_stud=50;//
readmarks(num_stud);
TopMark(mark,num_stud);
BottomMark(mark,num_stud);
return 0;
}
这样一来最后他就用BOTTOM MARK 的数据覆盖了我写入的TOP MARK的数据了…
求解… http://cpp.comsci.us/etymology/include/fstream/open.html
页:
[1]