I am trying to open a file in c++ and the server the progam in running on is based on tux.
string filename = "../dir/input.txt"; works but
string filename = "~jal/dir1/dir/input.txt"; fails
Is there any way to open a file in c++ when the filename provided is in the second format?
The
~jalexpansion is performed by the shell (bash/csh/whatever), not by the system itself, so your program is trying to look into the folder named~jal/, not/home/jal/.I’m not a C coder, but
getpwent()may be what you need.