Advertisement
Izsak

File creation program

Feb 9th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.    
  11.     int choice;
  12.     line11:
  13.     cout<< "Do you want to create a new file?\n";
  14.     cout<< "1) Yes\n";
  15.     cout<< "2) No\n";
  16.         cin>> choice; cin.get();
  17.  
  18.     if (choice == 1)
  19.     {
  20.    
  21.         string fileName;
  22.         cout<<"Enter filename";
  23.         getline(cin, fileName);
  24.         fstream myFile(fileName, ios::in | ios::out | ios::app);
  25.         string textInput;
  26.        
  27.         if (myFile.is_open())
  28.         {
  29.             cout<< "Enter text line by line, type end when finished\n";
  30.         while (textInput != "end")
  31.         {
  32.            
  33.             getline(cin, textInput);
  34.             myFile<< textInput << endl;
  35.         }
  36.         }
  37.         else
  38.         {
  39.             cout<<"ERROR:FILE NOT FOUND"<<endl;
  40.             cin.get();
  41.         }
  42.  
  43.     }
  44.     /* 
  45.     else if (choice == 2)
  46.     {
  47.         goto line33;
  48.     }
  49.  
  50.     else
  51.     {
  52.         cout<< "Invalid choice\n";
  53.         goto line11;
  54.     }
  55.    
  56. line33:;*/
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement