Reading Different length of inputs from a file

Hi again. I have a input file shown below. the format of the file is
first two data are string code,char status,then next three are char type,int reading1,reading2.
The first tow datas are fixed for all lines. but remaining data will be in the combination of 3 data.(char int int,char int int)
how do i read this?
sample input
JOHN1234 G R 1812 18000 B 1738 9300 B 504 4500
GARC5678 P R 862 17000
JEFF9445 G B 1405 14300 B 712 5900


My code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
while(!in.eof())
	{
		in>>cust_code>>cust_status>>unit_type1>>cust_E_usage>>cust_W_usage;
                    if(unit_type=='r')
                       bill=bill+(cust_E_usage*VALUE1);
                     else		
                         bill=bill+(cust_E_usage*VALUE2);		
		while(in>>unit_type2)
		{
			in>>cust_E_usage1>>cust_W_usage1;
			  if(unit_type=='r')
                          bill=bill+(cust_E_usage*VALUE1);
                          else		
                          bill=bill+(cust_E_usage*VALUE2);
			in.clear();
                          cout<<bill;
		}
		
	}
I have managed to write the code.it reading the first three lines . but after the third line it goes into a infinite loop.here is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while(!in.eof())
	{
		in>>cust_code>>cust_status;
		cout<<cust_code<<" "<<cust_status<<" ";
		
		while(in.peek()!='\n')
		{
			in>>unit_type>>cust_E_usage>>cust_W_usage;
			cout<<" "<<unit_type<<"  "<<cust_E_usage<<" "<<cust_W_usage;
		}
		
		cout<<endl;
		system("pause");
	}
Finally,got it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

in>>cust_code>>cust_status;
	while(in)
	{
		
		cout<<cust_code<<" "<<cust_status<<" ";
		while(in.peek()!='\n')
		{
			in>>unit_type>>cust_E_usage>>cust_W_usage;
			cout<<" "<<unit_type<<"  "<<cust_E_usage<<" "<<cust_W_usage;
		}
		
		cout<<endl;
		system("pause");
		in>>cust_code>>cust_status;	
		
	}
Topic archived. No new replies allowed.