473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.

Oct 10 '05 #1
2 3503
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.

Oct 10 '05 #2
"Brian Ronk" <pa***********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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.


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).
Oct 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alexandros | last post by:
I do something like this: ifstream file(argv); if(!file) //... file.read(buffer,BUFFSIZE); while(!file.eof()) { for(int i=0; i<BUFFSIZE; i++) // ... file.read(buffer,BUFFSIZE);
1
by: wtnt | last post by:
Hello. I've searched all over and haven't seen another thread with this problem. Please bear with me as I try to explain. thanks. :) I have some programs that need to be cross-platform...
7
by: Hamburgpear | last post by:
Dear All, Is it possible to reset the value of xxx.peek() after it reachs EOF ? Regards HP
2
by: Assertor | last post by:
Hi, All. (VC++6.0) I found some strange thins when using getline() and seekg() of std::ifstream. After the file position of an open file was shift to the end of the file, seekg() did not...
2
by: Karl | last post by:
Hey everyone! I've got a quick question on whether std::ifstream is buffered or not. The reason is that I have a homework assignment that requires me to benchmark copying files using different...
5
by: Kamran | last post by:
Hi, I am having problem using std::ifstream in my code under solaris. Everything works fine on linux but the same thing i.e. trying to read a binary file and fill in a struct result in complete...
3
by: toton | last post by:
Hi, I want to unread a few things while I am reading a file. One solution I know is putback the characters read to the buffer. But as I need frequent moving file pointer , to a few steps back, I...
2
by: Angus | last post by:
Hello Here is my code std::ifstream myfile; std::string line; long begin,end;
1
by: Vadim Volevach | last post by:
Hi, // Under C++Builder 2007 (+ Dinkumware) #include <fstream> using namespace std; int main (int argc, char* argv) { // Create a DOS-Text file, that has only two lines: // - the first...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.