0

Why is this not reading from the file

The contents of the file

123456 James.Watson 234567 12.Clover.Crescent Spanish.Town St.Catherine Single Standard Passprot
ifstream file;
		file.open( "guest.txt", ios::in );

		if ( !file )
			 {
				cerr << "File could not be opened" << endl;
				exit( 1 );
			 } 

		
		guest info1;

		while(file >> idnumber >> contact >> name >> street >> parish >> country >> category >> booking >> idtype )
		{	
			info1.setinfo(idnumber,contact,name,street,parish,country,category,booking,idtype);
			info1.display();
		}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by thelamb
0

You expect 9 variables, but the line only contains 8. Plus, the types that are in the file must match the types of the variables. E.g. if the line is

"hello"

Then:

int firstWord;
file >> firstWork;

won't work.

Lastly, you should put extra braces around the file >> etc. >> etc.:

while( (file >> idnumber >> contact >> name >> street >> parish >> country >> category >> booking >> idtype) )
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.