-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileio2.cpp
More file actions
79 lines (77 loc) · 1.76 KB
/
fileio2.cpp
File metadata and controls
79 lines (77 loc) · 1.76 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//Program to show file input output
#include<fstream>
#include<iostream>
using namespace std;
int main()
{
char buff[90];
char name[20];
int choice;
cout<<"Enter the appropriate option:"<<endl;
cout<<"1)Create new file 2)Open existing file and append";
cin>>choice;
switch (choice)
{
case 1:
{
cout<<"Enter the name of the file you want to create"<<endl;
cin>>name;
ofstream fout(name);
cout<<"Enter the data";
cin.ignore(1,'\n');
cin.getline(buff,90);
fout<<buff;
fout.close();
break;
}
case 2:
{
cout<<"Enter the name of the existing file"<<endl;
cin>>name;
ofstream fout(name,app);
if(!fout)
{
cout<<"The file you requested cannot be found"<<endl;
}
else
{
cout<<"Enter the data"<<endl;
cin.ignore(1,'\n');
cin.getline(buff,90);
fout<<buff;
}
fout.close();
break;
}
}
cout<<"The data has been entered"<<endl;
cout<<"Do you want to read the file1)yes2)no"<<endl;
cin>>choice;
switch (choice)
{
case 1:
{
char ch;
ifstream fin(name);
if(!fin)
{
cout<<"File cannot be found"<<endl;
}
else
{
while(fin.get(ch))
{
cout<<ch;
}
}
fin.close();
break;
}
case 2:
{
cout<<"exiting"<<endl;
break;
}
}
return 0;
}