Output 2 text files

Hey guys,

so I'm trying to output 2 different text files, one has customer names and the other has items they are selling. I gave each customer an ID and each of their items has the same ID. Only problem is when I try to output it, it only outputs the first item with the same ID. I do not want to display the ID number at all, I think getline would show it so I am not using it.

here's 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
	ifstream infile, infile2;
	string Fname, Lname, email, item, itemPrice;
	int id, itemID;

	infile.open("Data.txt");
	infile2.open("ItemList.txt");

	cout << " --- Current sellers --- \n";
	
	while(true)
	{
		infile >> id >> Fname >> Lname >> email;
		infile2 >> itemID >> item >> itemPrice;
		if(infile.eof()) break;
		cout << Fname << " " << Lname << " " << email << endl;

		
		if( id == itemID)
		{
			cout << item << " $" << itemPrice << endl;
			infile2 >> itemID >> item >> itemPrice;
		}
	}
	
	infile.close();
	infile2.close();


The output I'm trying to get is ~

John Smith johnsmith@mail.com
shoes $12
shirt $15

Guy Smith guysmith@mail.com
phone $50
....


here is what I actually get

John Smith johnsmith@mail.com
shoes $12

Guy Smith guysmith@mail.com
phone $50


The first customer shirt item isn't being outputted. Maybe I'm reading the or comparing the info wrong or just not seeing it, any help would be appreciated, thanks!
Make first customer have three items and you will got more serious problem.
You need to change whole logic here. You best bet is to read all info from files into some container(s) and then manipulate them. You might use, say std::map<int, std::pair<customer, std::vector<item>>>, where int will be an ID and customer and item is respective structs.
So would you read the files the same and then put them into vectors? Or read straight into a vector, I'm at a lost here sadly.
Topic archived. No new replies allowed.