c++写入txt文件

简单方式:

 1 #include "stdafx.h"  
 2 #include <iostream>
 3 #include <iomanip>
 4 #include <fstream>
 5 
 6 using namespace std;
 7 
 8 void write()
 9 {
10     ofstream out("C:\\Users\\hhx\\Desktop\\b.txt",ios::app);
11     if(!out){
12         cout << "Unable to open otfile";
13         exit(1); 
14 
15     }
16     printf("writting data into file C:\\Users\\hhx\\Desktop\\b.txt\n");
17     out<<"hello,"<<endl<<"world."<<endl;
18     out.close();
19 }

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

posted @ 2016-04-26 21:27  morein2008  阅读(3604)  评论(0编辑  收藏  举报