I am trying to read a binary file and I need to determine its size, but regardless of the method I tried, I get a zero size.
For instance:
fstream cbf(address, ios::binary | ios::in | ios::ate); fstream::pos_type size = cbf.tellg(); // Returns 0. char* chunk = new char[size]; cbf.read(chunk, size); //...
If I used the following:
#include <sys/stat.h> struct stat st; stat(address.c_str(),&st); int size = st.st_size;
The size is still zero. I also tried the following, but still zero.
File* fp; fp = open(address.c_str(), "rb");
How to get file size?
Thanks for the answers ... I identified the problem: The binary I was trying to get was created at runtime, and I just forgot to close it before trying to read it ...
source share