I'm trying to measure a filesize in Android using std::ifstream
. I found https://stackoverflow.com/a/5840160/5884503 and did this:
std::ifstream f;
f.open(filePath, std::ios_base::binary | std::ios::ate);
if (f.is_open()) {
ALOGV(TAG, "opened");
} else {
ALOGV(TAG, "problem opening");
}
auto size = f.tellg();
f.close();
__android_log_print(ANDROID_LOG_VERBOSE, "my tag", "filesize: %ld", size);
And I'm getting the filesize as 0
always, even though the file for sure exists and has more than 1mb.
I know this can be done with std::filesystem
but this is not already or badly supported on Android. So, how to do with std::ifstream
?
Could there be a problem with my formatting? I don't think so.