Using C++ to access file from Documents folder on iOS and Print the contents

void printFileInfo()
{

char *home = getenv(“HOME”);
char *subdir = “/Documents”;

std::stringstream ss;
ss << home << subdir << “/file.txt”;
std::string s = ss.str();

s.erase(0, strlen(“/private”)); // Erase “/Private” from the final string

char sss;

char letter ;
int i ;
std::string line ;

std::ifstream reader(s.c_str()) ;

if (!reader) {

std::cout << “Error opening input file” << std::endl ;
return -1 ;

}

for (i = 0; !reader.eof() ; i++) {

getline( reader , line ) ;
std::cout << s.c_str() << std::endl;
std::cout << line << std::endl ;

}
reader.close() ;

}

Advertisements