'std::filesystem::recursive_directory_iterator with consistent path separation?

I just noticed that std::filesystem::recursive_directory_iterator uses different path separateors (i.e. / vs \) depending on whether it's on Windows or Linux, is there a way to make it return paths with '/' to make it consistent across systems?

This is how I am getting the paths:

for(auto& path: fs::recursive_directory_iterator(dir_path))
{
    // Skip directories in the enumeration.
    if(fs::is_directory(path)) continue;
    string path_str = path.path().string();
}

What I mean is, the contents of path_str will be different between the two OSs (because the separators will be different), I would like them to be the same. I could just replace them on the final string, but that uses more cycles than if I can instruct the stl to use '/' for everything isntead.

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source