c++写入txt文件

时间:2024-09-02 17:05:56

简单方式:

 #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream> using namespace std; void write()
{
ofstream out("C:\\Users\\hhx\\Desktop\\b.txt",ios::app);
if(!out){
cout << "Unable to open otfile";
exit(); }
printf("writting data into file C:\\Users\\hhx\\Desktop\\b.txt\n");
out<<"hello,"<<endl<<"world."<<endl;
out.close();
}

参考:http://blog.****.net/qingcaichongchong/article/details/8217526