以C++方式读取文件内容,且另存为其他文件中

以C++方式读取文件内容,且另存为其他文件中

既然学习C++,就想以纯粹的C++方式读写文件内容。

功能实现代码段如下:

 

 1 #include 
 2 #include 
 3 #include <string>
 4 using namespace std;
 5 
 6 bool GetALineData()
 7 {
 8     ifstream in("I:\\testConsole.txt");
 9     // failbit/badbit 有效时,置位
10     if (in.fail()) 
11         cout << "Open file error!" << endl;
12 
13     ofstream out("I:\\log.txt", ofstream::app);
14 
15     string tmpStr;
16     unsigned int tmpInt;
17 
18     // 逐个读出I:\\testConsole.txt中的数据(以空格、换行符、制表符分隔开)
19     while (in >> tmpStr)
20     {
21         tmpInt = atoi(tmpStr.c_str());
22         cout << tmpInt << endl;
23         out << tmpInt << endl;
24     }
25 
26     in.close();
27 
28     return 0;
29 }

 

posted on 2014-04-14 00:27  海子的乐园 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yelo/p/3663119.html

你可能感兴趣的:(以C++方式读取文件内容,且另存为其他文件中)