In order to write to a file on sdcard to add android.permission.WRITE_EXTERNAL_STORAGE in AndroidManifest.xml. What need to add / do to keep a record of the device memory (flash / application folder)?
Write function:
bool write_to_file(const std::string & file_name, const std::string & text)
{
bool res = false;
std::ofstream stream (file_name.c_str (), std::ios::out);
stream.clear();
if (! stream.fail()) {
res = true;
stream << text.c_str() << std::endl;
}
else {
LOGE ("std :: ofstream: wtire error");
}
stream.close();
return res;
}
Call example
std::string file("/sdcard/text.txt");
write_to_file(file, "simple text"); // OK !!!
std::string file("./text.txt");
write_to_file(file, "simple text"); // ERROR !!!