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

前端 未结 7 1447
攒了一身酷
攒了一身酷 2020-12-29 20:53

I would like to write a function :

inline char separator()
{
    /* SOMETHING */
}

that returns the file separator of the system in standar

7条回答
  •  醉酒成梦
    2020-12-29 20:57

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

    inline char separator()
    {
    #ifdef _WIN32
        return '\\';
    #else
        return '/';
    #endif
    }
    

    or (as suggested by PaperBirdMaster)

    const char kPathSeparator =
    #ifdef _WIN32
                                '\\';
    #else
                                '/';
    #endif
    

提交回复
热议问题