平时总遇到将数据写到txt中的情况,尤其是在调试程序看中间结果时,所以将代码保存下来,方便以后应用:
ofstream outfile; string InitialFileName("Initial.txt"); string NewFileName("New.txt"); outfile.open(InitialFileName, ostream::app); /*以添加模式打开文件*/ outfile<<"----------------------------one frame-------------------------"<<endl; for (size_t i=0; i<g_vInitial.size(); i++) { outfile<<g_vInitial[i].x<<", "<<g_vInitial[i].y<<endl; } outfile.close(); /*关闭文件*/
C++输出数据到txt
时间: 2024-10-07 01:49:49