C++でファイル内容を読み込み、他のファイルとして保存

3694 ワード

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