Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <conio.h>
  5. #include <windows.h>
  6. #include <cstdlib>
  7. using namespace std;
  8.  
  9.  
  10. class FileManager {
  11. string fileopen; // nazwa pliku do otwarcia
  12. string createfile; // nazwa tworzonego pliku
  13. string text; // zawartość pliku
  14. ofstream outfile; // plik wyjciowy
  15. ifstream infile; // plik wejsciowy
  16. char c;
  17. string str;
  18. fstream is;
  19. const int n=500;
  20. bool isOpened = false;
  21.  
  22. public:
  23. int newfile()
  24. {
  25. system("cls");
  26.  
  27. cout <<"\t\t TWORZENIE PLIKU " <<endl;
  28. cout <<" Podaj nazwe pliku: ";
  29. cin >> str;
  30. cout <<"\t\t*********************" <<endl;
  31.  
  32. str = str + ".txt";
  33. std::ofstream o( str.c_str(), ios::app );
  34. isOpened = true;
  35.  
  36. return 0;
  37. }
  38.  
  39.  
  40. void showMenu()
  41. {
  42. while( true )
  43. {
  44. char opcje;
  45. do
  46. {
  47.  
  48. system("cls");
  49. cout <<"[1] Otworz plik \n" ;
  50. cout <<"[2] Edytowanie \n" ;
  51. cout <<"[3] Wyswietl zawartosc pliku \n" ;
  52. cout <<"[4] Nowy plik \n" ;
  53. cout <<"[5] Wyjscie \n" ;
  54. opcje =getch();
  55.  
  56. switch(opcje)
  57. {
  58. case '1':
  59. {
  60. openfile();
  61. }
  62. break;
  63. case '2':
  64. {
  65. editfile();
  66. }
  67. break;
  68. case '3':
  69. {
  70. showfile();
  71. }
  72. break;
  73. case '4':
  74. {
  75. newfile();
  76. }
  77. break;
  78. case '5':
  79. {
  80. exit (0);
  81. }
  82. break;
  83. }
  84. }
  85. while(true);
  86. }
  87. }
  88.  
  89. void showfile()
  90. {
  91. system("cls");
  92. is.open (str.c_str());
  93. if (is.is_open())
  94. {
  95. cout<<"'";
  96. while (is.good())
  97. {
  98. c = is.get();
  99. if (is.good())
  100. {
  101. cout << c;
  102. }
  103. }
  104. cout<<"'";
  105. is.close();
  106. }
  107. else
  108. {
  109. cout<<"Brak otwartego pliku";
  110. }
  111. cout<<"\n\nNacisnij dowolny przycik zeby wrocic do menu...";
  112. getch();
  113. showMenu();
  114. }
  115.  
  116. int openfile()
  117. {
  118. int i;
  119. char file,esc;
  120. system("cls");
  121. cin.sync();
  122. cout <<"\t\t OTWIERANIE PLIKU " <<endl<< endl;
  123. cout << "Podaj nazwe pliku ktory chcesz otworzyc: ";
  124. cin >> str;
  125.  
  126. cout <<"\t\t*************************" <<endl;
  127. is.open (str.c_str());
  128.  
  129. if (is.is_open())
  130. {
  131. while (is.good())
  132. {
  133. c = is.get();
  134. if (is.good())
  135. {
  136. cout << c;
  137. }
  138. }
  139. isOpened = true;
  140. is.close();
  141. while( true )
  142. {
  143. char opcje;
  144. do
  145. {
  146. cout << " " << endl;
  147. cout << " " << endl;
  148. cout << " Czy chcesz przejsc do edycji tego tekstu? ";
  149. cout <<"[1] Tak / [2] NIE\n" ;
  150.  
  151. opcje = getch();
  152.  
  153. switch(opcje)
  154. {
  155. case '1':
  156. {
  157. system("cls");
  158. editfile();
  159. }
  160. case '2':
  161. {
  162. system("cls");
  163. showMenu();
  164. }
  165. break;
  166. }
  167. }
  168. while(opcje != '1' & '2');
  169. return 0;
  170. }
  171.  
  172. }
  173. else
  174. {
  175. cout <<"Podany plik nie istnieje!";
  176. cout << "\nAby rozpoczac edycje, otworz plik\n";
  177. cout << "1. Sprobuj jeszcze raz\n";
  178. cout << "2. Exit\n";
  179. while( true )
  180. {
  181. char opcje;
  182. opcje = getch();
  183.  
  184. switch(opcje)
  185. {
  186. case '1':
  187. {
  188. system("cls");
  189. openfile();
  190. }
  191. case '2':
  192. {
  193. system("cls");
  194. showMenu();
  195. }
  196. break;
  197. }
  198. }
  199. }
  200.  
  201.  
  202. }
  203.  
  204.  
  205. int editfile ()
  206. {
  207. string textToAdd;
  208. int i;
  209. string slowo;
  210. ofstream plik;
  211. is.open (str.c_str());
  212.  
  213. cout <<"\t\t EDYCJA PLIKU " <<endl<< endl<<endl;
  214.  
  215. if (isOpened == true)
  216. {
  217. cout<<"Tresc pliku:\n";
  218. if (is.is_open())
  219. {
  220. while (is.good())
  221. {
  222. c = is.get();
  223. if (is.good())
  224. {
  225. cout << c;
  226. }
  227. }
  228. is.close();
  229. }
  230.  
  231. while( true )
  232. {
  233. char opcje2;
  234. do
  235. {
  236. cout <<endl<<endl;
  237. cout << "Czy chcesz cos dopisac?"<<endl;
  238. cout <<"[1] Tak / [2] NIE\n" <<endl;
  239. opcje2 = getch();
  240. switch(opcje2)
  241. {
  242. case '1':
  243. {
  244. outfile.open (str.c_str(), ios::app);
  245. cout << "\nPodaj tekst ktory ma byc dopisany:\n";
  246.  
  247. cin.sync(); // czysci bufor strumienia wejsciowego
  248. getline(cin, textToAdd);
  249.  
  250. for(i=0; i<textToAdd.length(); i++)
  251. {
  252. outfile << textToAdd[i];
  253. }
  254. outfile.close();
  255. break;
  256. }
  257. case '2':
  258. {
  259. showMenu();
  260. break;
  261. }
  262. }
  263.  
  264. }
  265. while(opcje2 != '2');
  266.  
  267.  
  268. plik.close();
  269. }
  270. }
  271. else
  272. {
  273. while( true )
  274. {
  275. cout << "\nAby rozpoczac edycje, otworz plik\n";
  276. cout << "1. Otworz plik\n";
  277. cout << "2. Exit\n";
  278. }
  279. }
  280. system ("Pause") ;
  281. return 0;
  282.  
  283. }
  284.  
  285. };
  286.  
  287.  
  288.  
  289.  
  290. int main()
  291. {
  292. int pozycja,znak;
  293. bool koniec = false;
  294. FileManager manager;
  295. manager.showMenu();
  296.  
  297. return 0;
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement