C++ Txt文档写入
void writefile(student *s,int n,string filepath){
ofstream myfile;
if(!myfile)//有错误
{
exit(1);
}else//文件存在 ,可以在文件末尾写入
{
myfile.open(filepath);
for(int i=0;i<n;i++){
myfile<<s[i].num<<" "<<s[i].name<<endl;
}
myfile.close();
}
}
//mifile.open(filepath,ios::app)可以在原文件末尾写入,而不覆盖之前文件内容。
浙公网安备 33010602011771号