Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <fstream>
  4. #include <string>
  5. using namespace std;
  6. void createfile();
  7. void rfile();
  8. void wfile();
  9. void tfile();
  10. int main ()
  11. {
  12. int op;
  13. do
  14. {
  15. system("cls");
  16. cout<<"1.c file"<<endl;
  17. cout<<"2.r file"<<endl;
  18. cout<<"3.w file"<<endl;
  19. cout<<"4.t file"<<endl;
  20. cout<<"5. exit"<<endl;
  21. cout<<"select 1/2/3/4/5"<<endl;
  22. cin>>op;
  23. switch(op)
  24. {
  25. case 1: createfile();system("pause");break;
  26. case 2:wfile();system("pause");break;
  27. case 3:rfile();system("pause");break;
  28. case 4:cout<<"4";system("pause");break;
  29. case 5:
  30. {
  31. char ch;
  32. cout<<"exit with <y>";
  33. cin>>ch;
  34. if (ch=='y')
  35. op=0;
  36. }
  37. default:
  38. cout<<"invalid operation"<<endl;
  39. break;
  40. }
  41. }
  42. while(op!=0);
  43. return 0;
  44. }
  45. void createfile()
  46. {
  47. fstream file("testfile.txt", ios::in|ios::out);
  48. file.close();
  49. }
  50. void wfile(){
  51. ofstream file;
  52. file.open("testfile.text");
  53. file<<"text";
  54. file.close();
  55. }
  56. void rfile()
  57. {
  58. ifstream file;
  59. file.open("testfile.text");
  60. string data;
  61. getline(file,data);
  62. cout<<data<<endl;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement