首页 > 编程语言 > 详细

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

时间:2014-04-14 08:15:12      阅读:556      评论:0      收藏:0      [点我收藏+]

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

功能实现代码段如下:

 

bubuko.com,布布扣
 1 #include <iostream>
 2 #include <fstream>
 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 }
bubuko.com,布布扣

 

以C++方式读取文件内容,且另存为其他文件中,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/yelo/p/3663119.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!