I am writing a cross-platform compatible function in C++ that creates directories based on input filenames. I need to know if the machine is Linux or windows and use the appropriate forward or back slash. For the following code below, if the machine is Linux then isLinux = true. How do I determine the OS?
bool isLinux;
std::string slash;
std::string directoryName;
if isLinux
slash = "/";
else
slash = "\\";
end
boost::filesystem::create_directory (full_path.native_directory_string() + slash + directoryName);
Use:
BTW, you can still safely use this slash “/” on Windows as windows understands this perfectly. So just sticking with “/” slash would solve problems for all OSes even like OpenVMS where path is
foo:[bar.bee]test.extcan be represented as/foo/bar/bee/test.ext.