This Blog is dedicated to Sir Johnson Lin
Learn flow chart from C language , master C with the chart!

c++ source code (copy text file by line )



D:\CPPcode\copytxtfile\copytxtfile.c++
 1 //++++++++++++++++++++++++++
 2  //      copytxtfile.cpp
 3  //++++++++++++++++++++++++++
 4  
 5  ///#include header
 6  #include <iostream>
 7  #include <fstream>
 8  
 9  
10  ///Using
11  using namespace std;
12  
13  
14  ///main_in
15  main(int argc,char *argv[])
16  {
17      
18      
19      ///declare
20      ifstream i_file;
21      ofstream o_file;
22      string sMytext;
23      
24      
25      /// Open i_file
26      i_file.open(argv[1]); 
27      //ifstream i_file(argv[1]);//declare then open
28      
29      
30      
31      ///Is file ?
32      if (i_file==NULL)
33      {
34          
35          
36          ///Prompt error!
37          cout << "Cannot open" << argv[1] << endl;
38          
39          
40          ///main_EXIT
41          return(1);
42          
43          
44          ///+
45      }//end if
46      
47      
48      ///Open o_file
49      o_file.open(argv[2]);
50      //ofstream o_file(argv[2);//declare then open
51      
52      
53      ///<Read line>
54      ///Loop to last line
55      while(getline (i_file, sMytext))
56      {
57          
58          
59          ///Write line+/n
60          o_file << sMytext<< "\n";
61          
62          
63          ///Display 1 line +endl
64          cout << sMytext<< endl;
65          
66          
67          ///+
68      }//end while
69      
70      
71      ///Close files
72      i_file.close(); 
73      o_file.close();
74      
75      
76      ///main_end
77      return 0;
78  } //main_end
79  
80  

沒有留言:

張貼留言