如何获得在标准的C / C ++文件分隔符:/或\\? [英] How to get the file separator symbol in standard C/C++ : / or \?

查看:330
本文介绍了如何获得在标准的C / C ++文件分隔符:/或\\?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个函数:

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

这将返回该系统在标准的C / C ++ / C ++ 11的文件分隔符? (我的意思是斜线或反斜线取决于系统)。有没有办法实现这一目标?

that returns the file separator of the system in standard C/C++/C++11 ? (I mean slash or backslash depending on the system). Is there a way to achieve this ?

推荐答案

我不知道如何做到这一点以外的其他检查的ifdef

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

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

或(如由PaperBirdMaster建议)

or (as suggested by PaperBirdMaster)

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

这篇关于如何获得在标准的C / C ++文件分隔符:/或\\?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆