forked from vishnuparikh/vmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11 FileOperations.cpp
More file actions
60 lines (52 loc) · 1.1 KB
/
Copy path11 FileOperations.cpp
File metadata and controls
60 lines (52 loc) · 1.1 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
/*
NINAD DESHPANDE
Roll No.:10
SE COMP II
Batch: S1
Assignment 11
Question:
Write a C++ program that creates an output file, writes information to it,
closes the file and open it again as an input file and read the information from the file.
*/
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
char name[80];
cout<<"Enter name of file to create\n";
cin>>name;
ofstream fout;
fout.open(name);
if(!fout)
{
cout<<"Error opening file\n";
exit(1);
}
cout<< "Writing to the file" <<endl;
cout<< "Enter contents for file end with ctrl+D";
string data;
while(getline(cin,data))
{
if(data == "^D")
break;
fout<< data <<endl;
}
fout.close();
ifstream fin;
fin.open(name);
if(!fin)
{
cout<<"Error opening file\n";
exit(1);
}
cout<< "Reading from the file" <<endl;
while(fin)
{
getline(fin,data);
cout<< data <<endl;
}
fin.close();
return 0;
}