Please, help me. I can't read binary file. The file's length is 198944, but my code reads 374. I tried to use fread, ifstream, WinAPI ReadFile. This is the function that reads file:
std::string ReadThisFile(std::string aPath) {
FILE *inputstream = fopen(aPath.c_str(),"rb");
long size;
size_t result;
fseek(inputstream,0,SEEK_END);
size = ftell(inputstream);
rewind(inputstream);
char *buff = new char [size];
result = fread (buff,1,size,inputstream);
std::string ret=buff;
fclose(inputstream);
delete[]buff;
return ret;
}
Any help is needed, thank you!
strlento get the final size? You can't do store binary content in a string.std::string? If not, use a different container. (like astd::vector<unsigned char>or something similar).fseek(binary_stream, offset, SEEK_END)is not guaranteed to work (according to the C standard from 1999).