I've got troubles loading a file into memory, my compiler warns me about something I do not grasp. What's the matter?
C:\Users\Caroline\Desktop\Prog\literature.cpp:236:15: warning: deleting array 'char chbuffer [(((sizetype)((ssizetype)fsize)) + 1)]' [enabled by default]
function :
bool loadfile(string & buffer, const char fpath[])
{
ifstream file(fpath, ios::binary);
if(!file) return false;
file.seekg(0, ios::end);
long fsize = file.tellg();
file.clear();
file.seekg(0);
char chbuffer[fsize + 1];
file.read(chbuffer, fsize);
buffer = chbuffer;
delete [] chbuffer;
return true;
}
You cannot delete
an automatically allocated array. Remove the delete [] chbuffer;
statement.
In general, delete
is only used when paired with new
. You could have allocated chbuffer
like this:
char *chbuffer = new char[fsize + 1];
in which case you would want to use delete [] chbuffer
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With