Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. class txtFile
  7. {
  8.     string fileName;
  9.  
  10.     public:
  11.         txtFile(string name)
  12.         {
  13.             fileName = name;
  14.         }
  15.  
  16.     void writeFile()
  17.     {
  18.         string data;
  19.         ofstream fileOutput;
  20.         fileOutput.open(fileName);
  21.         if (fileOutput.is_open())
  22.         {
  23.             cout << "File opened successfull" << endl;
  24.             fileOutput << "lol" << endl;
  25.             fileOutput << "lol2" << endl;
  26.             fileOutput.close();
  27.  
  28.         }else{
  29.             cout << "Failed to open a file" << endl;
  30.         }
  31.  
  32.     }
  33.     void readFile()
  34.     {
  35.         string data;
  36.         ifstream fileInput;
  37.         fileInput.open(fileName);
  38.         if (fileInput.is_open())
  39.         {
  40.             while(getline(fileInput, data))
  41.             {
  42.                 cout << data << endl;
  43.             }
  44.             fileInput.close();
  45.         }
  46.     }
  47.  
  48.  
  49.  
  50. };
  51.  
  52.  
  53. class fileManager
  54. {
  55.     txtFile *customerTextFile=NULL;
  56.     public:
  57.         fileManager(string fileName)
  58.         {
  59.             customerTextFile = new txtFile(fileName);
  60.         }
  61.  
  62.         ~fileManager()
  63.         {
  64.             delete customerTextFile;
  65.         }
  66.  
  67.         void write()
  68.         {
  69.             customerTextFile -> writeFile();
  70.         }
  71.  
  72.         void read()
  73.         {
  74.             customerTextFile -> readFile();
  75.         }
  76. };
  77.  
  78.  
  79. int main()
  80. {
  81.     fileManager file1("ciwczenie2.txt");
  82.     file1.write();
  83.     file1.read();
  84.  
  85.  
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement