I am using the cstdio (stdio.h)
to read and write data from binary files. I have to use this library due to legacy code and it must be cross-platform compatible with Windows and Linux. I have a FILE* basefile_
which I use to read in the variables configLabelLength
and configLabel
, where configLabelLength
tells me how much memory to allocate for configLabel
.
unsigned int configLabelLength; // 4 bytes
char* configLabel = 0; // Variable length
fread((char *) &configLabelLength, 1, sizeof configLabelLength, baseFile_);
configLabel = new char[configLabelLength];
fread(configLabel,1, configLabelLength,baseFile_);
delete [] configLabel; // Free memory allocated for char array
configLabel = 0; // Be sure the deallocated memory isn't used
Is there a way to read in configLabel
without using a pointer? For example is there a solution where I can use the c++ vector library or something where I do not have to worry about pointer memory management.