Advertisement
Masfiq

File#5: copy from a file and paste on other file

Jan 21st, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /*
  2. *   Masfiq
  3. *   21 January, 2017
  4. *
  5. *   Topic: file open in different mode
  6. */
  7.  
  8. /*  file naqqmr: string
  9. Saudi Arab
  10. Bangladesh
  11. Iran
  12. Iraq
  13. Syria
  14. */
  15.  
  16. #include<iostream>
  17. #include<fstream>
  18. using namespace std;
  19.  
  20. int main(){
  21.  
  22.     ofstream out_file;
  23.     out_file.open("new file.txt");
  24.     ifstream in_file;
  25.     in_file.open("string.txt");
  26.     char* str = new char[20];
  27.     while(true){
  28.         in_file.getline(str, 20);
  29.  
  30.         if(in_file.eof())
  31.             break;
  32.  
  33.         cout<<str<<endl;
  34.         out_file.write(str, 20);
  35.         out_file<<'\n';
  36.     }
  37.  
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement