Squish this Android NDK File Access Bug

  android, android-ndk, c++, file

I cannot figure out why this solution will let me open and modify files bytes with ofstream/ifstream, but reads/writes will not update the pointer accessed through tellp / tellg function calls.

This is a sample that does not work:

std::ofstream oStream(path,std::fstream::beg | std::fstream::binary);
int test = 98;
LOGI("OSTREAM POINTf :: %d", oStream.tellp());
oStream.write((char *)&test,4);
LOGI("OSTREAM POINT :: %d", oStream.tellp());
oStream.close();
oStream.clear();

In Both cases, the above Log’s: 0

It cannot be said that it is not writing to the files. Because I can easily write and read any bytes I want. The problem is that, it can only read/write bytes @ the beginning of the file.

This permission is provided to my manifest, and I have ensured it is permitted on the device itself.

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Source: Windows Questions C++

LEAVE A COMMENT