Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain platform's path separator using Boost.Filesystem

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.

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 \.

I also know I can use #ifdef _WIN32, but I'd prefer that Boost.Filesystem tell me the appropriate separator character.

EDIT: I want to use version 3 of the Boost.Filesystem API, as used in Boost 1.48.

like image 620
Emile Cormier Avatar asked Dec 05 '11 11:12

Emile Cormier


1 Answers

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.

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.

Simple example:

#include <boost/filesystem.hpp>
#include <iostream>

int main() {
    std::cout << boost::filesystem::path::preferred_separator << std::endl;
}
like image 194
fhntv24 Avatar answered Sep 16 '22 14:09

fhntv24