I am coding a C++ file and I want the code to know the path to the exe, that the code will be compiled and linked to. So whatever folder a user moves the exe to, the exe will be able to know the path of its host folder. I understand this is not the same as the current working directory, but I could be wrong!
My objective is for the exe to open files that will reside in the same folder as it regardless of where the user may put the exe.
The code has to be able to append the name of a file, that it wants to open, to this path (with a suitable path delimiter of course) and then open the file. This means that the path returned by whatever function/object does this has to be a std::string or can be read into a std::string.
I have tried:
path = std::experimental::filesystem::current_path();
std::string strPath (pthPath);
but the path object returned can't be written to strPath. (FYI: I need to use std::experimental because my IDE (VS2017) does not seem to have std::filesystem). The compiler reports that it can't convert parameter 1 from "std::experimental::filesystem::v1::path" to the string.
I get a similar error if I try
std::string strPath (to_string(pthPath));
Does anyone know how to resolve this or of a better way to meet the same objective?