-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read_Write.cpp
93 lines (87 loc) · 2.08 KB
/
Read_Write.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
82
83
84
85
86
87
88
89
90
91
92
93
//
//Richard Lynch
// 12302202
// Data Structures and Algorithms
// Hash Tables Assignment
//
#include "Read_Write.hpp"
Read_Write::Read_Write()
{
Stored = NULL;
Num_Stored = 0;
}
//readFile(names, &teststrings[0], &NUM_TEST_KEYS);
//
// --Read in test data--
bool Read_Write::readFile(string Input, string Output[], int* Num_Entries, int Output_Size)
{
ifstream *In = new ifstream;
In->open(Input);
if (In->fail()) //if fail outout error
{
cout << "Could not open Input file." << endl;
In->close();
return false;
}
else
{
cout << "Input file opened successfully." << endl;
int i = 0;
string Line;
getline(*In, Line);
for (Line; (i < Output_Size); getline(*In, Line))
{
Output[i] = Line;
//(*NUM_TEST_KEYS2)++;
i++;
}
*Num_Entries = i;
In->close();
return true;
}
}
//--eo Read Test Data--//
bool Read_Write::writeFile(string Output, int Input1[], int Num_Entries)
{
ofstream *Out = new ofstream;
Out->open(Output);
if (Out->fail()) //if fail outout error
{
cout << "Could not open Output file." << endl;
Out->close();
return false;
}
else
{
cout << "Output file opened successfully." << endl;
for (int i = 0; i < Num_Entries; i++)
{
*Out << i << ", " << Input1[i] << endl;
}
*Out << endl;
Out->close();
return true;
}
}
bool Read_Write::writeFile2(string Output, int Input1[], int Input2[], int Num_Entries)
{
ofstream *Out = new ofstream;
Out->open(Output, std::ofstream::app);
if (Out->fail()) //if fail outout error
{
cout << "Could not open Output file." << endl;
Out->close();
return false;
}
else
{
cout << "Output file opened successfully." << endl;
for (int i = 0; i < Num_Entries; i++)
{
*Out << Input1[i] << "," << Input2[i] << endl;
}
*Out << endl;
Out->close();
return true;
}
}