Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > ifstream --- error maybe?

Reply
Thread Tools

ifstream --- error maybe?

 
 
Jason
Guest
Posts: n/a
 
      10-28-2004
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
 
Reply With Quote
 
 
 
 
Niels Dybdahl
Guest
Posts: n/a
 
      10-28-2004
> 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


 
Reply With Quote
 
 
 
 
Jacek Dziedzic
Guest
Posts: n/a
 
      10-28-2004
Jason wrote:

> 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.
 
Reply With Quote
 
Tom Widmer
Guest
Posts: n/a
 
      10-28-2004
On 27 Oct 2004 20:36:58 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Jason) wrote:

>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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Error Text from ifstream Johannes Bauer C++ 6 11-21-2007 10:03 AM
get integer values using ifstream error. zhouchengly@gmail.com C++ 7 11-07-2006 12:58 PM
(help) Runtime error in ifstream/ios class Massimo Soricetti C++ 2 01-14-2006 12:02 PM
error when initialize ifstream with string Lingyun Yang C++ 2 04-11-2004 01:55 AM
error passing ifstream. why? Giulio C++ 2 06-24-2003 09:19 PM



Advertisments