| View previous topic :: View next topic |
| Author |
Message |
Jason Guest
|
Posted: Thu Oct 28, 2004 3:36 am Post subject: ifstream --- error maybe? |
|
|
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
|
Posted: Thu Oct 28, 2004 8:47 am Post subject: Re: ifstream --- error maybe? |
|
|
| 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
|
Posted: Thu Oct 28, 2004 9:43 am Post subject: Re: ifstream --- error maybe? |
|
|
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
|
Posted: Thu Oct 28, 2004 11:20 am Post subject: Re: ifstream --- error maybe? |
|
|
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 |
|
 |
|