How to generate a OS independent path in c++

c++, cross-platform, filesystems

Solution

If you wanted to do it at compile time you could certainly do something like

#ifdef WIN32
#define OS_SEP '\\'
#else
#define OS_SEP '/'
#endif

Or you could just use '/' and things will work just fine on windows (except for older programs that parse the string and only work with '\'). It only looks funny if displayed to the user that way.

Problem

I have a destination path and a file name as strings and I want to concatenate them with c++. Is there a way to do this and let the program/compiler choose between / and \ for windows or unix systems?

Original source