-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex55.cpp
More file actions
executable file
·78 lines (62 loc) · 1.27 KB
/
Copy pathex55.cpp
File metadata and controls
executable file
·78 lines (62 loc) · 1.27 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
/*
CPSC 121-0X
Paul De Palma
depalma
Example 55
*/
//Graceful open and graceful close
//Simple character i/o
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream* gfopenIn(string);
ofstream* gfopenOut(string);
void doStuff(ifstream*,ofstream*);
int main()
{
string fileIn, fileOut;
ifstream* fin;
ofstream* fout;
cout << "Enter an input file name" << endl;
getline(cin,fileIn);
cout << "Enter an output file name" << endl;
getline(cin,fileOut);
fin = gfopenIn(fileIn);
fout = gfopenOut(fileOut);
doStuff(fin,fout);
//notice the member access operators, necessary with pointers
fin->close();
fout->close();
return 0;
}
ifstream* gfopenIn(string fileIn)
{
ifstream* fin = new ifstream;
fin->open(fileIn);
if (!fin->fail())
return fin;
cout << "Error opening input file: " << fileIn << endl;
exit(0);
}
ofstream* gfopenOut(string fileOut)
{
ofstream* fout = new ofstream;
fout->open(fileOut);
if (!fout->fail())
return fout;
cout << "Error opening output file: " << fileOut << endl;
exit(0);
}
void doStuff(ifstream* fin, ofstream* fout)
{
char ch;
fin->get(ch);
while(*fin) //why the dereference operator. Take a guess.
{
if (islower(ch))
ch = toupper(ch);
fout->put(ch);
fin->get(ch);
}
}