【问题标题】:boost::locale::to_lower throw bad_cast exceptionboost::locale::to_lower 抛出 bad_cast 异常
【发布时间】:2023-03-28 17:43:01
【问题描述】:

在 Win 7 64 位和 VS2010 上提升 1.54 x64。编译为“Release x64”并运行以下代码:

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

抛出std::bad_cast 异常。即使添加后也没有任何变化(如其他地方所建议的那样):

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

或将to_lower(y) 更改为:to_lower(y, mylocale) 或使用std::string 而不是std::wstring 或在环境中设置LANG。

目标是转换为小写的意大利语 UTF-8 单词。我没有发现这样的问题,所以我认为这是我的机器特定问题或 boost 库问题。顺便说一句,我已经从 sourceforge 下载了预编译的 boost 库(boost_1_54_0-msvc-10.0-64.exe)。任何想法? 谢谢! 马里奥

【问题讨论】:

  • 如果你使用 utf8,那么wstring 按照定义似乎是不可能的

标签: c++ boost boost-locale


【解决方案1】:

当您的语言环境传递给boost::locale::to_lower(默认为std::locale(),即全局语言环境的副本)没有安装boost::locale::converter 方面时,将引发此异常。 See this for the related documentation.

改用boost::locale::generator 创建语言环境。 (另请参阅文档链接的示例,例如 this one。)

【讨论】:

  • 谢谢,现在可以了。我错误地认为 std::locale lx; 和 boost::locale::generator gen; std::locale lx=gen(""); 是等价的。
猜你喜欢
  • 2012-10-19
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多