ifstream read() loop

E

eiji

Hi folks,

I'm new to binary-file handling and try to work/learn playing around
with MD5.
Now everything works fine with small files, but when files get
bigger(e.g. 28MB) this loop stops in the second read()! I don't know
why!

typedef basic_ifstream<unsigned char> ifstream_uc;
void MD5::update (unsinged char *input, unsinged int input_length)
{...}

void MD5::update(ifstream_uc& stream){

unsigned char ubuffer[1024];
unsigned int len;

while (stream.good()){
cout << ( stream.rdstate( ) & ios::badbit ) << endl;
cout << ( stream.rdstate( ) & ios::failbit ) << endl;
cout << ( stream.rdstate( ) & ios::eofbit ) << endl << endl;

stream.read(ubuffer, 1024); // note that return value of read is
unusable.

cout << ( stream.rdstate( ) & ios::badbit ) << endl;
cout << ( stream.rdstate( ) & ios::failbit ) << endl;
cout << ( stream.rdstate( ) & ios::eofbit ) << endl << endl << endl;

len=static_cast<unsigned int>(stream.gcount());

update(ubuffer, len);
}

}
0
0
0

0
0
0

0
0
0

0
2
1

Regards,
eiji
 
E

eiji

I "solved" the problem, just changing:

ifstream_uc file(filename);
to:
ifstream_uc file(filename, ios::binary);

This flag is not well documented. So what is the result of
opening in ios::binary-mode?
Stroustrup didn't say something about that.
I will move on "googleing".

Thanks,
Sascha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top