1,先清空文件在写ofstream out("filename",ios::out);2,接着写ofstream out("filename",ios::out | ios:;append);out.write("\n",1); //换行写方式差异在于:打开文件时选择的参数不同。