Hi I not good in c how can i turn my program to read inputs from a file and to write outputs to another file in c++
            Asked
            
        
        
            Active
            
        
            Viewed 197 times
        
    -3
            
            
        - 
                    Do you have a write a program? Why not issue a 'cp' system command from the program? – Danish Mar 11 '11 at 19:48
- 
                    3`program < in_file > out_file` ? – Eugen Constantin Dinca Mar 11 '11 at 19:49
- 
                    This is the kind of question where you really need to either [read a book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) or search first. [c++ file input](http://stackoverflow.com/search?q=c%2B%2B+file+input) and [c++ file write](http://stackoverflow.com/search?q=c%2B%2B+file+write) – Bill the Lizard Mar 11 '11 at 20:02
2 Answers
1
            
            
        #include <fstream>
#include <string>
int main(){
 //Open file for reading
 std::ifstream in("input.dat");
 //Open file for writing
 std::ofstream out("output.dat");
 //Temporary buffer for line read from file
 std::string line;
 while(getline(in,line)){//getline removes the newline char
      out<<line<<'\n';   // Appending back newline char  
 }
 return 0;
}
 
    
    
        reggie
        
- 13,313
- 13
- 41
- 57
 
    