-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.cpp
63 lines (52 loc) · 1 KB
/
files.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void write_file(char *str){
ofstream out;
char data[100];
out.open(str, ios::out | ios::app);
cout<<"File created"<<endl;
cout<<"Enter the data to be entered in file"<<endl;
cin.ignore();
cin.getline(data, 100);
out<<data<<endl;
}
void read_file(char *str) {
ifstream in;
char data[100];
in.open(str, ios::in);
in.get(data, 100);
cout<<data<<endl;
}
void delete_file(char *str) {
if(remove(str)!=0)
cout<<"Error deleteing file!";
else
cout<<"file successfully deleted!";
}
int main() {
char file[100];
int choice;
cout<<"Enter the file name : ";
gets(file);
cout<<endl<<"1. Write"<<endl<<"2. Read"<<endl<<"3. Delete"<<endl;
cin>>choice;
switch(choice) {
case 1: {
write_file(file);
break;
}
case 2: {
read_file(file);
break;
}
case 3: {
remove(file);
break;
}
default : {
cout<<"wrong input";break;
}
}
}