我有一些麻烦使用Boost :: Locale(1.49)在Debian 7 GNU / Linux上(版本的GCC版为4.6.3-1)。代码保存在CP1251中。使用像“isalpha”(或“boost :: algorithm :: is_alpha”)的函数,最终有异常(bad_cast)。看起来这个检查没有正确的方面。这是代码:

#include <iostream>

#include <boost/locale.hpp>

int main ()
{
  boost::locale::generator gen;
  std::locale loc(gen.generate("ru_RU.cp1251"));
  unsigned char debug501 = 'Б';
  bool debug500 = std::isalpha(debug501, loc);
  std::cout<< debug500;

  return 0;
}
.

它在Windows 7上运行,Windows 7与Visual Studio 2008上。但是,在这种情况下,仍有一个问题:“debug500”设置为false。只有当像素生成这样的语言环境时,它才能正常工作:std::locale loc(".1251")。但是,当通过Boost生成语言环境时,会出现同样的问题:std::locale loc(boost::locale::generator().generate("ru_RU.cp1251"));。 如果有人可以解释代码和/或如何使用Boost和STD与CP1251语言环境一起制作类似的检查(ISAlpha),我会感激。

有帮助吗?

解决方案

替换:

unsigned char debug501 = 'Б';
.

char debug501 = 'Б';
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top