Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. int main(int argc, char** argv)
  2. {
  3. using namespace std;
  4.  
  5. if (argc < 3)
  6. { // we didn't get enough arguments, so complain and quit
  7. cout << "Usage: " << argv[0] /* program name */ << " infile outfile" << endl;
  8. exit(1);
  9. }
  10. // get the file names from the argument array
  11. char* inFileName = argv[1];
  12. char* outFileName = argv[2];
  13. int temp; // hold the number being transfered
  14.  
  15. // open the files
  16. ifstream inFile;
  17. inFile.open(inFileName);
  18. if (inFile.fail())
  19. {
  20. cout << "Could not open " << inFileName << endl;
  21. exit(1);
  22. }
  23. ofstream outFile;
  24. outFile.open(outFileName);
  25. if (outFile.fail())
  26. {
  27. cout << "Could not open " << outFileName << endl;
  28. exit(1);
  29. }
  30.  
  31. // ok, the files are open; let's copy
  32. while (inFile >> temp)
  33. {
  34. outFile << temp << endl; // one number per line
  35. }
  36.  
  37. // close up the files
  38. inFile.close();
  39. outFile.close();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement