Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <conio.h>
- #include <windows.h>
- #include <cstdlib>
- using namespace std;
- class FileManager {
- string fileopen; // nazwa pliku do otwarcia
- string createfile; // nazwa tworzonego pliku
- string text; // zawartość pliku
- ofstream outfile; // plik wyjciowy
- ifstream infile; // plik wejsciowy
- char c;
- string str;
- fstream is;
- const int n=500;
- bool isOpened = false;
- public:
- int newfile()
- {
- system("cls");
- cout <<"\t\t TWORZENIE PLIKU " <<endl;
- cout <<" Podaj nazwe pliku: ";
- cin >> str;
- cout <<"\t\t*********************" <<endl;
- str = str + ".txt";
- std::ofstream o( str.c_str(), ios::app );
- isOpened = true;
- return 0;
- }
- void showMenu()
- {
- while( true )
- {
- char opcje;
- do
- {
- system("cls");
- cout <<"[1] Otworz plik \n" ;
- cout <<"[2] Edytowanie \n" ;
- cout <<"[3] Wyswietl zawartosc pliku \n" ;
- cout <<"[4] Nowy plik \n" ;
- cout <<"[5] Wyjscie \n" ;
- opcje =getch();
- switch(opcje)
- {
- case '1':
- {
- openfile();
- }
- break;
- case '2':
- {
- editfile();
- }
- break;
- case '3':
- {
- showfile();
- }
- break;
- case '4':
- {
- newfile();
- }
- break;
- case '5':
- {
- exit (0);
- }
- break;
- }
- }
- while(true);
- }
- }
- void showfile()
- {
- system("cls");
- is.open (str.c_str());
- if (is.is_open())
- {
- cout<<"'";
- while (is.good())
- {
- c = is.get();
- if (is.good())
- {
- cout << c;
- }
- }
- cout<<"'";
- is.close();
- }
- else
- {
- cout<<"Brak otwartego pliku";
- }
- cout<<"\n\nNacisnij dowolny przycik zeby wrocic do menu...";
- getch();
- showMenu();
- }
- int openfile()
- {
- int i;
- char file,esc;
- system("cls");
- cin.sync();
- cout <<"\t\t OTWIERANIE PLIKU " <<endl<< endl;
- cout << "Podaj nazwe pliku ktory chcesz otworzyc: ";
- cin >> str;
- cout <<"\t\t*************************" <<endl;
- is.open (str.c_str());
- if (is.is_open())
- {
- while (is.good())
- {
- c = is.get();
- if (is.good())
- {
- cout << c;
- }
- }
- isOpened = true;
- is.close();
- while( true )
- {
- char opcje;
- do
- {
- cout << " " << endl;
- cout << " " << endl;
- cout << " Czy chcesz przejsc do edycji tego tekstu? ";
- cout <<"[1] Tak / [2] NIE\n" ;
- opcje = getch();
- switch(opcje)
- {
- case '1':
- {
- system("cls");
- editfile();
- }
- case '2':
- {
- system("cls");
- showMenu();
- }
- break;
- }
- }
- while(opcje != '1' & '2');
- return 0;
- }
- }
- else
- {
- cout <<"Podany plik nie istnieje!";
- cout << "\nAby rozpoczac edycje, otworz plik\n";
- cout << "1. Sprobuj jeszcze raz\n";
- cout << "2. Exit\n";
- while( true )
- {
- char opcje;
- opcje = getch();
- switch(opcje)
- {
- case '1':
- {
- system("cls");
- openfile();
- }
- case '2':
- {
- system("cls");
- showMenu();
- }
- break;
- }
- }
- }
- }
- int editfile ()
- {
- string textToAdd;
- int i;
- string slowo;
- ofstream plik;
- is.open (str.c_str());
- cout <<"\t\t EDYCJA PLIKU " <<endl<< endl<<endl;
- if (isOpened == true)
- {
- cout<<"Tresc pliku:\n";
- if (is.is_open())
- {
- while (is.good())
- {
- c = is.get();
- if (is.good())
- {
- cout << c;
- }
- }
- is.close();
- }
- while( true )
- {
- char opcje2;
- do
- {
- cout <<endl<<endl;
- cout << "Czy chcesz cos dopisac?"<<endl;
- cout <<"[1] Tak / [2] NIE\n" <<endl;
- opcje2 = getch();
- switch(opcje2)
- {
- case '1':
- {
- outfile.open (str.c_str(), ios::app);
- cout << "\nPodaj tekst ktory ma byc dopisany:\n";
- cin.sync(); // czysci bufor strumienia wejsciowego
- getline(cin, textToAdd);
- for(i=0; i<textToAdd.length(); i++)
- {
- outfile << textToAdd[i];
- }
- outfile.close();
- break;
- }
- case '2':
- {
- showMenu();
- break;
- }
- }
- }
- while(opcje2 != '2');
- plik.close();
- }
- }
- else
- {
- while( true )
- {
- cout << "\nAby rozpoczac edycje, otworz plik\n";
- cout << "1. Otworz plik\n";
- cout << "2. Exit\n";
- }
- }
- system ("Pause") ;
- return 0;
- }
- };
- int main()
- {
- int pozycja,znak;
- bool koniec = false;
- FileManager manager;
- manager.showMenu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement