for loop/array issue

I am making a script for a final project for class that is supposed to calculate the bill for a lawn mowing service. Everything works good except for one for loop. The for loop reads the input file for the customers name and addrass, the number of jobs, and the amount of hour/minutes for the jobs. The first round of the for loop works like it is supposed to, but on every following trip through it ignores the first 8 characters of the customers name. Instead of "Castor Julia Maude James" I get "ulia Maude James". Everything else works like intended. My code for the for loop is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	for(int j=0; j<numofcust; j++)
	{
		getline(infile, name_[j]);
		getline(infile, address1_[j]);
		getline(infile, address2_[j]);
		infile >> jobs_[j];
		totaljobs=totaljobs+jobs_[j];
		while(i<totaljobs)
		{
			infile >> hours_[i] >> mins_[i];
			i=i+1;
		}
		infile.ignore('\n');
	}


The input file is as follows(I cannot change this.)

Davis Rocky James
156 High St
Cleveland TN 37311
5
1 34
2 45
1 55
2 45
0 30

Saucy Steven Adams
12 Wildwood Court
Cleveland TN 37311
1
1 30

Castor Julia Maude James
56423 Fox Loop
Cleveland TN 37311
3
1 34
2 45
1 30

If I comment out the infile.ignore('\n') it throws off the reading of the file.

Thanks in advance for help!
hi,
This was a hard one to find.

instead of
 
    infile.ignore('\n');


first variable is number of characters to ignore

you should use
 
   infile.ignore(2);


which discards 2 newline characters one from the last (hour min) and one
for the blank line.

Hope this was helpful
Shredded
Worked great! Thanks for your help!
Topic archived. No new replies allowed.