»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 04-18-2004, 05:29 PM   #1 (permalink)
Registered User
 
Join Date: Jun 2003
Location: Maine
Posts: 24
Elburn is on a distinguished road
Simple C++ loop question

I can't believe I can't figure this out. I'm just trying to read from a file, a one line list of numbers. But if I have 3 numbers in the list, it will read the first two fine, but for some reason it doesn't read the third. I've tried switching up the order of things and nothing has helped. What am I doing wrong?

Code:
inputfile>>temp;
	
	while (!inputfile.eof())
	{
		cout<<temp<<' ';
		amountof++;				//Determining how many numbers there are
		inputfile>>temp;
	}
-Elburn

Elburn is offline   Reply With Quote
Old 04-18-2004, 05:54 PM   #2 (permalink)
Registered User
 
elmers's Avatar
 
Join Date: Sep 2003
Location: Euroland
Posts: 397
elmers is on a distinguished road
Lol it reads the last number in then it checks the loop and since its finished it quits.

while (!inputfile.eof())
{
inputfile>>temp;
cout<<temp<<' ';
amountof++;
}

Does this work for you?
elmers is offline   Reply With Quote
Old 04-18-2004, 05:57 PM   #3 (permalink)
Registered User
 
elmers's Avatar
 
Join Date: Sep 2003
Location: Euroland
Posts: 397
elmers is on a distinguished road
Or you can add this line:

inputfile>>temp;
while (!inputfile.eof())
{
cout<<temp<<' ';
amountof++;
inputfile>>temp;
}
cout<<temp<<' ';
elmers is offline   Reply With Quote
Old 04-18-2004, 06:03 PM   #4 (permalink)
Registered User
 
Join Date: Jun 2003
Location: Maine
Posts: 24
Elburn is on a distinguished road
Haha, whoops.

Yup, that helps. Thanks a lot
Elburn is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 06:53 PM.