I ran into a problem with the boost filestreams: I need to create and modify files in the user directory under windows. However the username contains an umlaut which makes this fail when compiled under MinGW as the standard is missing the wide_char open() API for filestreams which boost uses. see Read/Write file with unicode file name with plain C++/Boost, UTF-8-compliant IOstreams and https://svn.boost.org/trac10/ticket/9968
However I ran across the line, that this problem mainly occurs when trying to use a character outside the systems codepage. In my case I'm using only characters from the systems codepage as obviously the users directory exists. This makes me think, that this should work, if I could tell boost::path to expect all std::string
s as beeing UTF8 but converting them to the system encoding when calling the string()
member function (which happens in boost::fstream::open
)
So basically: Is there any way to do that conversion (UTF8->system encoding) automatically using boost (and boost Locale)?
To be complete here is my code for setting the locale:
#ifdef _WIN32
// On windows we want to enforce the encoding (mostly UTF8). Also using "" would use the default which uses "wrong" separators
std::locale::global(boost::locale::generator().generate("C"));
#else
// In linux / OSX this suffices
std::locale::global(std::locale::classic());
#endif // _WIN32
// Use also the encoding (mostly UTF8) for bfs paths
bfs::path::imbue(std::locale());