Reading data from a file

I'm working on a homework problem that requires me to get a name from the user, and then compare that name to names from a file that I've been given.

If the name is found in the list, then I need to output it's place in the list(number). The data is in this format:

Number Boy_Name Girl_Name
1 Josh Emily
2 Jake Samantha
3 Alan Stephanie

ect.

The issue I'm having is that I can't seem to get the data to read into my variables correctly.

1
2
3
4
5
6
7
while(!input.eof()){

		input >> name_number >> boy >> girl;

		cout << "name_number is: " << name_number << endl;
		cout << "boy is: " << boy << endl;
		cout << "girl is: " << girl << endl;


This is the small bit of code that I'm having problems with. It seems that it's just reading in the same data over and over again, and not getting the next name in the list. Here is some sample output:

Please select your name to compare.
Walter
name_number is: 1
boy is: Jacob
girl is: Emily

The name Walter was not on the list for boys.
The name Walter was not on the list for girls.

name_number is: 1
boy is: Jacob
girl is: Emily

The name Walter was not on the list for boys.
The name Walter was not on the list for girls.
Press any key to continue . . .

I've been reading through my text book and googling around for a bit, any hints as to the solution to this part of the problem would be much appreciated.



Last edited on
First, you need an array. You probably have one, but I don't see any.

Second, the code doesn't show that it's searching for the name, so it won't find it.

Third, your code shows that it's outputting everything that goes into it.

If these are small pieces of code you posted in one code block, then nobody can actually see what you're trying to do, or what's wrong with the code. Edit out some parts and compile it a few times to find out where the code went wrong, then post what exactly went wrong.
Topic archived. No new replies allowed.