I am trying to hard code into C++ program to look for config.ini in the same directory as the executable, without knowing the complete path to the file. I am trying to find a way to make a local reference to the executable.
Basically load (“./config.ini”)
without doing
(“C:\foo\bar\config.ini”)
You want
GetModuleFilename()on Windows (pass NULL to get filename of current executable). Otherwise, callboost::filesystem::initial_path()early in the program (see Boost docs in link for the reason to do this early). That should cover most of the situations.Edit
Brain malfunction. We always start our programs from the executable’s directory, so the
boost::initial_path()thing works, but it won’t work so well if you start the program from another direcory. Sorry for the confusion on that. On Windows, though, I’d get the path fromGetModuleFilenameand useboost::pathto manipulate the result.