C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ifstream read() loop

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
eiji
Guest





PostPosted: Mon Jan 30, 2006 9:00 pm    Post subject: ifstream read() loop Reply with quote



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);
}

}

Quote:

0

0
0

0
0
0

0
0
0

0
2
1

Regards,
eiji
Back to top
eiji
Guest





PostPosted: Mon Jan 30, 2006 11:00 pm    Post subject: Re: ifstream read() loop Reply with quote



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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.