Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. //Kevin Pham
  2. //Lab 04 CIS22A
  3. //This lab shows us how to copy a file from a folder to copy and save it into another or same folder.
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. ifstream inputFile;
  14. ofstream outputFile;
  15.  
  16. string temp;
  17. string filenameIn;
  18. string filenameOut;
  19.  
  20. int i = 1;
  21. while (i)
  22. {
  23. cout << "Please enter a FILE NAME:"; //Type out the File you want to copy for example: FILE NAME.txt
  24. getline(cin, filenameIn);
  25. inputFile.open(filenameIn);
  26.  
  27. if (inputFile.fail())
  28. {
  29. cout << "Please try again, Invalid Input... " << endl;
  30. }
  31. else
  32. {
  33. i = 0;
  34. }
  35. }
  36.  
  37. i = 1;
  38. while (i) {
  39. cout << "Please enter the destination FILE NAME: ";//File Destination: H:\Visual Studio 2017\Projects\Examples/ FILE NAME.txt
  40. getline(cin, filenameOut);
  41. outputFile.open(filenameOut);
  42. if (outputFile.fail())
  43. {
  44. cout << "Please try again, Invalid Input... " << endl;
  45. }
  46. else {
  47. i = 0;
  48. }
  49. }
  50.  
  51. getline(inputFile, temp);
  52.  
  53. outputFile << temp << endl;
  54.  
  55.  
  56.  
  57. inputFile.close();
  58. outputFile.close();
  59.  
  60. cout << "Your Done!! Its Copied..." << endl;
  61.  
  62. system("pause");
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement