ja************@gmail.com sade:
Howdy,
I am having a weird problem with ifstream.
ifstream img;
img.open(im_fn.c_str(),ios::in|ios::binary);
char *x = new char[65000];
if(!img) {
cerr << "Error: problem reading img" << endl;
exit(1);
}
img.get(x,65000);
cout << img.tellg() << " " << endl;
The output from this is:
64302
I would have thought I would get 64999. Any further reads cause the
ifstream to fall into fail state (tellg returns -1). The weirdest part
is this occurs only for some (typically large) files and stops at the
different bytes for different files. I have tried both g++ and MS2003
compilers so it is not compiler dependent (as I had initially thought
with a problem this weird).
-----------------------------------------------------------------------
istream_type&
get(char_type* s, streamsize n, char_type delim);
Extracts characters and stores them into successive locations of an
array whose first element is designated by s. Characters are extracted
and stored until any of the following occurs:
* n-1 characters are stored
* An end-of-file on the input sequence
* The next available input character == delim.
* An Exception
If the function stores no characters, it calls the basic_ios member
function setstate(failbit), which may throw ios_base::failure. In any
case, it stores a null character into the next successive location of
the array.
-----------------------------------------------------------------------
istream_type&
get(char_type* s, streamsize n);
Calls get(s,n,widen("\n")).
-----------------------------------------------------------------------
TB