4

Boost 1.54 x64 on Win 7 64bits and VS2010. Compiling as "Release x64" and running the following code:

#include <boost/locale/conversion.hpp>
std::wstring y = L"NoNseNSE";
std::wstring w = boost::locale::to_lower(y);

throw std::bad_cast exception. Nothing changes even after adding (as suggested elsewhere):

std::locale mylocale("");
std::locale::global(mylocale);

or changing to_lower(y) to: to_lower(y, mylocale) or using std::string instead of std::wstring or setting LANG in the environment.

The goal is to convert to lowercase Italian UTF-8 words. I don't have found around problems like this, so I presume it is my machine specific problem or a boost library problem. BTW I have downloaded the precompiled boost library (boost_1_54_0-msvc-10.0-64.exe) from sourceforge. Any idea? Thanks! mario

SiliconValley
  • 1,465
  • 17
  • 30

1 Answers1

9

This exception is thrown when your locale passed to boost::locale::to_lower (by default std::locale(), that is a copy of the global locale) does not have a boost::locale::converter facet installed. See this for the related documentation.

Use a boost::locale::generator to create the locale instead. (See also the examples linked to by the documentation, for example this one.)

Aleph
  • 1,209
  • 10
  • 19
  • Thanks, now it works. I was wrongly convinced `std::locale lx;` and `boost::locale::generator gen; std::locale lx=gen("");` were equivalent. – SiliconValley Nov 03 '13 at 10:56