1

C++ ifstream read from absolute path in Linux [closed]

view story
linux-howto

http://stackoverflow.com – This is something that I can't explain at all. I use this piece of code to read a text file: ifstream ifile("myfile.txt"); if (ifile.is_open()) { ifile.seekg (0, ifstream::end); long flength = ifile.tellg(); if (flength>0) { ifile.seekg(0, ios::beg); char* text = new char[flength + 1]; ifile.read(text, flength); text[flength] = '\0'; printf("Text: %s\n", text); } ifile.close(); } In this case the file myfile.txt is located in the same directory as the executable or the folder from which I call it using the terminal. I get the te (HowTos)