473,396 Members | 1,764 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.read fails mysteriously

Hi. I have the following problem; VC++ project, there's this code
operation on 500Mb file via ifstream, POS_TYPE for this case is
unsigned int which is 32-bit long.

//dataFile.good() returns 1 here. File is open in binary mode
dataFile.seekg(someValue, ios::beg); // someValue is ~247M
//dataFile.tellg() gives someValue correctly here.
POS_TYPE* dataBuffer = new POS_TYPE[someValue2]; //someValue2 is ~4k
dataFile.read((char*)dataBuffer, someValue2 * sizeof(POS_TYPE));
//at this point, gcount returns 138, bad() gives 0, and eof() and
fail() both return 1.

The interesting thing is that the error is persistent (at least for an
hour while I was debugging this) and occurs at specific locations,
while on others, including the locations closer to the end of file, it
doesn't occur.
I tried copying the file back and forth and it seems to be ok (e.g.
not bad sectors or anything).

What can be causing it? Is there any way to get a more detailed error
message?
Feb 20 '08 #1
1 2262
Woops. File was not actually open in binary mode, nevermind.
Feb 20 '08 #2

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

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
2
by: Joe | last post by:
Hello - I use a ifstream to open a file in my code. I read through it using getline() and then I close() it. Later in the code I try to open the same file but it fails. Here is the code: ...
4
by: Joe | last post by:
Hello - I wrote a program that uses ifstream to open an ASCII file and getline() to read in the lines. The problem is when I try to open the same file again later in the code. I used close()...
6
by: Ram Laxman | last post by:
Iam new bie to C++ programming.. I want to write a program which will read the Comma separated values(CSV) file column wise. For example: In a.txt: "TicketNumber","Phone","CarNumber"...
4
by: Dr. Len | last post by:
Hi all! Given that I have a binary file which contains 4-byte integer values in sequence and I know in advance how many there are, does the C++ standard have any algorithm or like method to read...
7
by: shawn | last post by:
Hi All, Am using MSVC6 compiler on a WinXP machine. Am trying to read a file using std::ofstream; the problem is that Tofstream.is_open() fails and Tifstream.rdstate() returns "2" which...
3
by: Earl Purple | last post by:
This is a simple function to split a file into multiple files (archives) of a fixed size. The last one will contain any remaining bytes. Here is the implementation: #include <cstdio>...
10
by: SpreadTooThin | last post by:
I just did a loop ifstream i(myfile, ios::binary); while (!i.eof()) { i.read(buff, 2); } Well it should have come out of the loop but it tried to do the read
11
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.