Connecting Tech Pros Worldwide Help | Site Map

ifstream.seekg failing

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 10th, 2005, 07:15 PM
Brian Ronk
Guest
 
Posts: n/a
Default ifstream.seekg failing

I'm having a strange error. I have a Debian stable server and I'm
using gcc 3.3, but it looks like I have 3.4 installed as well. I
recently made a change to a program that takes data from two files and
converts it into csv format so the final files don't have an extension
of any kind. When I did this, I began having problems with one of my
input files. This file is scanned through, and then it is returned to
the beginning at the beginning of my loop. It looks like the seekg
that I'm using is failing. Here's the line that I'm using:

// stateData is the name of the input file variable
stateData.seekg(0, ios::beg);
// I also tried stateData.seekg((streamoff) 0), but it didn't help.

Unfortunetly, I haven't been doing much programming recently, so I'm
getting a bit rusty, and I dont' know some of the newer features
(namespaces and some more advanced things like that). I've been trying
to figure out what's going on with no success, all I know is that
statData.tellg() is -1 after 1 run through of the file. The first loop
goes fine, and stops in the middle of the file, the next gives me -1.
If anyone can point me in some sort of direction, that would be great.
Thanks.


  #2  
Old October 10th, 2005, 07:45 PM
Brian Ronk
Guest
 
Posts: n/a
Default Re: ifstream.seekg failing

I just figured it out. For some reason, after I was done searching the
file, I called stateData.close(). Now the question becomes, why the
heck did it work before? It makes sense why it wasn't working now, you
can't go the beginning of a file that's closed. That's a bit hard to
do. Oh well. Thanks anyway.

  #3  
Old October 11th, 2005, 10:05 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: ifstream.seekg failing

"Brian Ronk" <paladin.rithe@gmail.com> wrote in message
news:1128973176.110746.193260@g43g2000cwa.googlegr oups.com...[color=blue]
>I just figured it out. For some reason, after I was done searching the
> file, I called stateData.close(). Now the question becomes, why the
> heck did it work before? It makes sense why it wasn't working now, you
> can't go the beginning of a file that's closed. That's a bit hard to
> do. Oh well. Thanks anyway.[/color]

Easy enough to answer the question "why the heck did it work before?".

Undefined behavior.

Undefined means it can do anything (including looking like it's working).


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.