-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_handling_1.cpp
81 lines (68 loc) · 1.33 KB
/
file_handling_1.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int checkFile(string, ofstream &);
void displayContent(fstream &);
void showStatus(fstream &);
int main()
{
ofstream outfile;
fstream myfile;
string str, filename;
char letter;
int n = 0;
cout << "\nEnter file name: ";
cin >> filename;
filename += ".txt";
myfile.open("myfile.txt");
if(!myfile)
{
exit(1);
}
if(checkFile(filename, outfile))
{
cout << "\nFile not opened!";
}
else
{
while(!myfile.eof())
{
myfile.get(letter);
outfile.put(tolower(letter));
cout << "\nConversion done baby!";
}
}
myfile.close();
return 0;
}
int checkFile(string name, ofstream &filee)
{
filee.open(name.c_str());
if(filee.fail())
{
return 1;
}
return 0;
}
void displayContent(fstream &filee)
{
string word;
while(!filee.eof())
{
for(int i = 0; i < 4; i++)
{
filee >> word;
cout << word << " ";
}
cout << endl;
}
}
void showStatus(fstream &filee)
{
cout << "\neof bit: " << filee.eof();
cout << "\nbad bit: " << filee.bad();
cout << "\ngood bit: " << filee.good();
cout << "\nfail bit: " << filee.fail();
filee.clear();
}