xcode - Open method opens files with full path only C++ -
file opens if write full path (full-path/roots.txt). file fails open if write filename (roots.txt)
and yet, roots.txt in same folder main.cpp. there settings should check on xcode?
here's code:
string line; ifstream infile; infile.clear(); // infile.open("roots.txt"); infile.open("/users/programming/c++/roots/roots.txt"); if (infile.fail()) cout << "could not open file: " << strerror(errno); getline(infile, line); cout << line;
if works when attempt open file absolute path , fails filename, relative path incorrect. ensure roots.txt
placed in current working directory. getcwd
function declared in unistd.h
.
Comments
Post a Comment