View Full Version : the memory is not pure
mickey
13th July 2007, 22:55
memblock = new char [size];
ifile.seekg (0, ios::beg);
ifile.read (memblock, size);
out.write (memblock, size);
Hi, when I write, file linked to out fstream, at the end, contain some caracters, that there aren't in the input file...... how avoid that caracters?
thanks
marcel
14th July 2007, 17:15
That is probably because "size" is bigger than the actual file size...
When you allocate memblock, it will contain some (rubbish) data(since you don't initialize it-e.g. memset, etc ).
When you read from the input file, the first "size" bytes in memblock will be overwritten with data from the file, but the rest will remain.
How do you compute "size" anyway?
Regards
mickey
14th July 2007, 17:58
int size;
size = ifile.tellg();
marcel
14th July 2007, 18:10
Querying the file pointer after you first open the file will return 0.
Try this:
ifile.seekg( -1, ios_base::end );
If this does not work, could you compare the size with the actual file size?
Regards
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.