How to get the file separator symbol in standard C/C++ : / or \?

I’m not sure how to do it other than by checking ifdefs

inline char separator()
{
#ifdef _WIN32
    return '\\';
#else
    return "https://stackoverflow.com/";
#endif
}

or (as suggested by PaperBirdMaster)

const char kPathSeparator =
#ifdef _WIN32
                            '\\';
#else
                            "https://stackoverflow.com/";
#endif

Leave a Comment