Skip to content

Instantly share code, notes, and snippets.

@LGLTeam
Created April 19, 2021 13:45
Show Gist options
  • Save LGLTeam/9ba745b7d25965956580d63624f6937b to your computer and use it in GitHub Desktop.
Save LGLTeam/9ba745b7d25965956580d63624f6937b to your computer and use it in GitHub Desktop.
Reading and writing text file via c++ for Android. No root
#include <string.h>
#include <cstring>
#include <fstream>
#include <iostream>
std::string dir = "/data/data/uk.lgl.modmenu/cache/imei";
std::string buf = "whatever";
std::ifstream myfile(dir);
if (!myfile.is_open()) {
std::ofstream os(dir.c_str(), std::ios::trunc);
os.write(buf.c_str(), buf.length());
os.close();
}
std::ifstream getfile("/data/data/uk.lgl.modmenu/cache/imei");
std::string line;
if (myfile.is_open())
{
while (getline (getfile,line) )
{
std::cout << line << '\n';
}
myfile.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment