[homework] Converting one format to another

Apr 7, 2013 at 11:14pm
I am in a c++ class and my group is having a hard time making this work... It keeps saying that 'fileOne.open' isn't working. We can't seem to figure out why. Any help would be greatly appreciated. Thank you in advance.

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

#include <iostream>
#include <string>
#include <fstream>
#include "convert.hpp"
using namespace std;

int main()
{
	HydraRecord hClientOne;
	HydraRecord hClientTwo;
	HydraRecord hClientThree;
	HydraRecord hClientFour;
	KrebStarRecord kClient;
	ifstream fileOne;
	ifstream fileTwo;
	ifstream fileThree;
	ifstream fileFour;
	ifstream index;
	ofstream outFile;
	int userResponse;
	int numRecords;
	string One;
	string Two;
	string Three;
	string Four;
	
	outFile.open("records.ksrf");
	
	cout << "Welcome to the record transfer system." << endl;
	cout << "======================================="<<endl;
	
	
	index.open("index.txt");
	if(index.is_open() == false){
		cerr << "ERROR: Cannot open input file. Exiting. [index]" << endl;
		return 1;
	}
	
	index >> numRecords;
	index.ignore(256, '\n');
	
	for (int i = 0; i < numRecords; i++){
		index >> One;
		index >> Two;
		index >> Three;
		index >> Four;
		}
		
	fileOne.open(One.c_str());
	if(fileOne.is_open() == false){
		cerr << "ERROR: Cannot open input file 1. Exiting." << endl;
		return 1;
	}
	fileTwo.open(Two.c_str());
	if(fileTwo.is_open() == false){
		cerr << "ERROR: Cannot open input file 2. Exiting." << endl;
		return 1;
	}
	fileThree.open(Three.c_str());
	if(fileThree.is_open() == false){
		cerr << "ERROR: Cannot open input file 3. Exiting." << endl;
		return 1;
	}
	fileFour.open(Four.c_str());
	if(fileFour.is_open() == false){
		cerr << "ERROR: Cannot open input file 4. Exiting." << endl;
		return 1;
	
	}
	
	fileOne >> numRecords;
	for (int i = 0; i < numRecords; i++){
		fileOne >> hClientOne.customerID;
		fileOne >> hClientOne.customerName;
		fileOne >> hClientOne.customerStreetAddress;
		fileOne >> hClientOne.Address[3];
		fileOne >> hClientOne.customerPhoneNumber;
		fileOne >> hClientOne.dateCreated[3];
		fileOne >> hClientOne.checkingBalance;
		fileOne >> hClientOne.savingBalance;
	}
	
	//convertHydraToKrebStar(hClient);
	
	outFile << "<?xml version=""1.0""?>"<<endl;
	outFile	<< "<ksrf>"<<endl;
	outFile	<< "	<customer>"<< endl;
	outFile	<< "		<id>" << kClient.customerID << "</id>"<<endl;
	outFile	<< "		<name>" << kClient.customerName << "</name>"<<endl;
	outFile	<< "		<address>"<<endl;
	outFile	<< "			<street>" << kClient.customerStreetAddress << "</street>"<<endl;
	outFile	<< "			<city>" << kClient.customerCity << "</city>"<<endl;
	outFile	<< "			<state>" << kClient.customerState << "</state>"<<endl;
	outFile	<< "			<zip>" << kClient.customerZip << "</zip>"<<endl;
	outFile	<< "		</address>"<<endl;
	outFile	<< "		<phone>" << kClient.customerPhoneNumber << "</phone>"<<endl;
	outFile	<< " 		<date>"<<endl;
	outFile	<< "			<year>" << kClient.yearCreated << "</date>"<<endl;
	outFile	<< "			<month>" << kClient.monthCreated << "</month>"<<endl;
	outFile	<< " 			<day>" << kClient.dayCreated << "</day>" << endl;
	outFile	<< "		</date>" << endl;
	outFile	<< " 		<accounts>"<< endl;
	outFile	<< "			<checking>" << kClient.checkingBalance << "</checking>" << endl;
	outFile	<< "			<savings>" << kClient.savingBalance << "</savings>"<< endl;
	outFile	<< "		</accounts>"<< endl;
	outFile	<< "	</customer>" << endl;
	outFile	<< "=======================================================================";
	
	outFile << "</ksrf>";
	index.close();
	outFile.close();
}
Last edited on Apr 7, 2013 at 11:16pm
Apr 7, 2013 at 11:55pm
Okay, we've fixed the 'fileOne' problem, but now file four isn't opening... any help is still appreciated. Thank you in advance.
Apr 8, 2013 at 12:19am
Your code for opening all the files are the same, so I doubt there's any problem there. Did you check to make sure that the string Four actually contains the correct file name?

I can't help but feel there's something wrong with using a loop to read in file names like this.
43
44
45
46
47
48
	for (int i = 0; i < numRecords; i++){
		index >> One;
		index >> Two;
		index >> Three;
		index >> Four;
		}
Apr 9, 2013 at 3:54am
Yea I fixed that one thank you so much for your reply.. I have another problem posted now though... It would be great if you'd take a look at it...
Topic archived. No new replies allowed.