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();
		}

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) )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.