Advertisement

A stupid FStream question

Started by June 30, 2000 02:36 PM
2 comments, last by WymsicalWyvern 24 years, 5 months ago
i''m having some problems getting this fstream to work, i only have like 1 book to go by, and i find that information on the net on fstream is very scarce, so i''ve cometo my most reliable source of help my problem is with reading teh data from the file *hangs head in shame*. I first get teh file size, then i create an array of BYTEs to hold the data, then call theStream.read( pointertodataspot, filesize), but gcount() always returns 0, could someone tell me what i''m doing wrong? i get teh right file size,and windows tells me its the same size so i''m totaly confused. here is a snippet from my code: //// Get the File Size theStream.seekg( 0, ios::end ); fileLength = theStream.tellg() - 1; pDIB = new unsigned char[ fileLength ]; theStream.read( &pDIB[0], fileLength ); int a = theStream.gcount(); a always seems to be 0 thankyou in advance The Wymsical Wyvern
Shouldn''t you be seeking back to the beginning before trying to read in the data?



- null_pointer
Sabre Multimedia
Advertisement
ok heres the problem
theStream.seekg( 0, ios::end );

then after playing with some vars you do this
theStream.read( &pDIB[0], fileLength );

the problem is the seekg moves the read postion to the end of the file....
then read trys to read in the file but your at the end so theres nothing to read
so just before you read put this line in:
theStream.seekg(0,ios::beg);
now your back at the begining of the file....
your read will work...

btw &pDIB[0] ummm this does work but personal I think it would be easier just to do it like this:
theStream.read( pDIB, fileLength );

its 4 keystrokes less and I think it looks better like this =)

Great Milenko

Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."


http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech

The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."
thankyou both for your help. this was truely a stupid mistake, now i feel stupid, but before i go to my room and hide my head ina pillow, about teh &pDIB[0] was merely a hacking attempt at seeing if it was a pointer problem since my grasp on pointers is.... i''ve said enough. thankyou again

The Wymsical Wyvern

This topic is closed to new replies.

Advertisement