ifstream --- error maybe?

J

Jason

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
 
N

Niels Dybdahl

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
 
J

Jacek Dziedzic

Jason said:
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.
 
T

Tom Widmer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top