C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ifstream --- error maybe?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Jason
Guest





PostPosted: Thu Oct 28, 2004 3:36 am    Post subject: ifstream --- error maybe? Reply with quote



I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.

Jason
Back to top
Niels Dybdahl
Guest





PostPosted: Thu Oct 28, 2004 8:47 am    Post subject: Re: ifstream --- error maybe? Reply with quote



Quote:
I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.

Reduce the code to the smallest amount that still produces the problem and
post that code.

Niels Dybdahl



Back to top
Jacek Dziedzic
Guest





PostPosted: Thu Oct 28, 2004 9:43 am    Post subject: Re: ifstream --- error maybe? Reply with quote



Jason wrote:

Quote:
I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.

Yes. Post the code. We are programmers, not clairvoyants.

- J.

Back to top
Tom Widmer
Guest





PostPosted: Thu Oct 28, 2004 11:20 am    Post subject: Re: ifstream --- error maybe? Reply with quote

On 27 Oct 2004 20:36:58 -0700, [email]jspalding (AT) gmail (DOT) com[/email] (Jason) wrote:

Quote:
I wrote a piece of code that reads read in about 1000 int values from
a text file. I put a cout statement to verify that the input in the
code was working as anticipated. It seems to work fine until some
point when it just ouputs 0's. So I then took the code and made a app
that just read the file and it worked fine.

Does anyone have a suggestion.

How are you checking for the end of the input? You should do something
like this:

int i = 0;
for(; i != 1000; ++i)
{
int val;
if (!(stream >> val))
break;
//assign val to whatever
}

if (i < 1000)
{
//something went wrong
//check stream.eof(), stream.bad() and stream.fail().
}

Tom

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.