-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.cpp
More file actions
49 lines (43 loc) · 663 Bytes
/
Copy pathfile.cpp
File metadata and controls
49 lines (43 loc) · 663 Bytes
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
//file IO cpp
#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;
}