Obtain platform's path separator using Boost.Filesystem

前端 未结 3 1930
梦毁少年i
梦毁少年i 2021-02-05 10:16

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.

3条回答
  •  爱一瞬间的悲伤
    2021-02-05 11:04

    It seems like boost::filesystem::path::make_preferred is the ticket:

    Effects: The contained pathname is converted to the preferred native format. [Note: On Windows, the effect is to replace slashes with backslashes. On POSIX, there is no effect. -- end note]

    Example:

    namespace bfs = boost::filesystem;
    bfs::path slash("/");
    bfs::path::string_type preferredSlash = slash.make_preferred().native();
    

提交回复
热议问题