Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class txtFile
- {
- string fileName;
- public:
- txtFile(string name)
- {
- fileName = name;
- }
- void writeFile()
- {
- string data;
- ofstream fileOutput;
- fileOutput.open(fileName);
- if (fileOutput.is_open())
- {
- cout << "File opened successfull" << endl;
- fileOutput << "lol" << endl;
- fileOutput << "lol2" << endl;
- fileOutput.close();
- }else{
- cout << "Failed to open a file" << endl;
- }
- }
- void readFile()
- {
- string data;
- ifstream fileInput;
- fileInput.open(fileName);
- if (fileInput.is_open())
- {
- while(getline(fileInput, data))
- {
- cout << data << endl;
- }
- fileInput.close();
- }
- }
- };
- class fileManager
- {
- txtFile *customerTextFile=NULL;
- public:
- fileManager(string fileName)
- {
- customerTextFile = new txtFile(fileName);
- }
- ~fileManager()
- {
- delete customerTextFile;
- }
- void write()
- {
- customerTextFile -> writeFile();
- }
- void read()
- {
- customerTextFile -> readFile();
- }
- };
- int main()
- {
- fileManager file1("ciwczenie2.txt");
- file1.write();
- file1.read();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement