获得使用Boost.Filesystem的平台的路径分隔符 [英] Obtain platform's path separator using Boost.Filesystem
问题描述
有没有办法使用,以获得该平台的路径分隔符 Boost.Filesystem的?通过路径分隔符,我的意思是 /
Unix和 \\
适用于Windows。
Is there a way to obtain the platform's path separator character using Boost.Filesystem? By path separator, I mean /
for Unix and \
for Windows.
我已经知道我可以使用的boost ::文件系统::路径::运营商/
用适当的分隔符来连接两个路径在一起。但我只想为 /
或 \\
。
I already know I can use boost::filesystem::path::operator/
to concatenate two paths together with the appropriate separator character. But I just want either /
or \
.
我也知道我可以使用的#ifdef _WIN32
,但我preFER了Boost.Filesystem的告诉我,适当的分隔符。
I also know I can use #ifdef _WIN32
, but I'd prefer that Boost.Filesystem tell me the appropriate separator character.
编辑:
我想使用Boost.Filesystem的API的版本3 ,如升压1.48使用
I want to use version 3 of the Boost.Filesystem API, as used in Boost 1.48.
推荐答案
随着1.57版本,提振现在有一个更好的解决办法,那就是不断的字符
/ wchar_t的
(取决于不同的平台上):的boost ::文件系统::路径:: preferred_separator
As of version 1.57, Boost now has a better solution, that is just constant char
/ wchar_t
( dependent on different platforms ): boost::filesystem::path::preferred_separator
.
读<一个href=\"http://www.boost.org/doc/libs/release/libs/filesystem/doc/reference.html#Operating-system-examples\" rel=\"nofollow\">http://www.boost.org/doc/libs/release/libs/filesystem/doc/reference.html#Operating-system-examples了解更多信息。还有它更依赖于系统的功能。
Read http://www.boost.org/doc/libs/release/libs/filesystem/doc/reference.html#Operating-system-examples for more information. There are even more system-dependent features in it.
简单的例子:
#include <boost/filesystem.hpp>
#include <iostream>
int main() {
std::cout << boost::filesystem::path::preferred_separator << std::endl;
}
这篇关于获得使用Boost.Filesystem的平台的路径分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!