Input/Output file help

The goal of what I'm doing is to take input from InputFile1, check it against all the values of InputFile2 to find a matching account number and amount and then if it finds a match, store the account number, amount and result in Output File, and then continue for all of the contents of InputFile1.

the contents of InputFile1 are in this format: 1234567, 123.00
the contents of InputFile2 are in the format: 00001234567, 123.00, A

The Output file is empty and is meant to put a comma between accountnumber1, amount1, and result.

When I compile it, nothing is written to the outputFile.

I included a counter in the second while loop to see if its looping correctly and the counter is reaching 962 and stopping if that indicates anything?

This is my code.

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
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
	char fillComma = ',';

	char result,
		zeroChecker;

	int	peekNum;


	ifstream firstFile,
		secondFile;

	string amount1,
		amount2,
		accountNumber1,
		accountNumber2,
		compareSecond;
	
	ofstream finalFile;


	//prompting the user for the file names
	/*
	cout << "Enter the name of the first file you want to use as input: ";
	cin >> firstName;
	cout << endl;

	cout << "Enter the name of the file taken from EAS: ";
	cin >> secondName;
	cout << endl;

	cout << "Enter the name of the file you want the final product stored to: ";
	cin >> finalName;
	cout << endl;

	*/



	// opening the files
	firstFile.open("InputFile1.txt");
	secondFile.open("InputFile2.txt");
	finalFile.open("OutputFile.txt");

		while (!firstFile.eof())
		{
			{
				//grabbing the name of the first account name to be compared to the second account name
				getline(firstFile, accountNumber1, fillComma);
				getline(firstFile, amount1);

				// removing the zeroes from the account name in the second file
			

				

				// cycling through all the accounts in the second file until an account with a matching name and amount are found
				while (!secondFile.eof())
				{
					getline(secondFile, accountNumber2, fillComma);

					accountNumber2.erase(0, accountNumber2.find_first_not_of('0'));
					getline(secondFile, amount2, fillComma);
					secondFile.get(result);
					//if an account with a mathing name and amount are found storing the information in the final file
					if (accountNumber1 == accountNumber2 && amount1 == amount2)
					{
						finalFile << accountNumber1 << fillComma << amount1 << fillComma << result << endl;
						cout << accountNumber1 << fillComma << amount1 << fillComma << result << endl; 
					}
					// if no matching accounts are found continuing the cycle
					getline(secondFile, accountNumber2, fillComma);
				}
			}
			
		}
	

	firstFile.close();
	secondFile.close();
	finalFile.close();
	return 0;
}
Last edited on
Your making it harder than it has to be.

To find the matching Acct# and amount, you just have to search file 2 for the "line" string in file 1.

1234567, 123.00

Last edited on
I'm sorry what do you mean by search file 2 for the "line" string?
Take the line as a whole to be one string, not separating into account number and amount, then search the second file for this string as a whole
If I take it as one string, the input from the second file is going to include the result variable that the first file won't have and it will break the search.
Topic archived. No new replies allowed.