Boost logo

Boost :

From: Alexei Alexandrov (alexei.alexandrov_at_[hidden])
Date: 2008-01-25 07:10:49


Hi,

I'm trying to use fs::wpath on Linux and I'm encountering some problems with
internal conversion of wide strings to external representation. The problem can
be demonstrated with the following code:

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

namespace fs = boost::filesystem;
int main()
{
    // Setting the global locale to be environment locale
    std::locale::global(std::locale(""));

    // Setting the wpath locale to be global
    fs::wpath_traits::imbue(std::locale());

    fs::wpath mypath(L"/tmp/some/directory");
    fs::create_directories(mypath);
}

To me, this work looks correct and should work.
But it terminates with the following message:

terminate called after throwing an instance of
'boost::filesystem::basic_filesystem_error<
boost::filesystem::basic_path<std::basic_string<wchar_t,
std::char_traits<wchar_t>, std::allocator<wchar_t> >,
boost::filesystem::wpath_traits> >'
  what(): boost::filesystem::wpath::to_external conversion error
Aborted

At the same time, the following code works:

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

#include <libs/filesystem/src/utf8_codecvt_facet.hpp>

namespace fs = boost::filesystem;
int main()
{
    fs::detail::utf8_codecvt_facet utf8_facet;
    std::locale loc( std::locale(), &utf8_facet );
    fs::wpath_traits::imbue( loc );

    fs::wpath mypath(L"/tmp/some/directory");
    fs::create_directories(mypath);
}

which uses a UTF-8 facet from boost itself.

The first example should work too - this is my understanding. Who is wrong here
- me or boost?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk