3

我在 Debian 7 GNU/Linux(GCC 版本为 4.6.3-1)上使用 boost::locale (1.49) 时遇到了一些麻烦。代码保存在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;
}

它在装有 Visual Studio 2008 的 Windows 7 上毫无例外地运行。但是,仍然存在一个问题:在这种情况下,“debug500”设置为 false。仅当像这样生成语言环境时它才能正常工作:std::locale loc(".1251"). 但是当 locale 由 boost: 生成时,也会出现同样的问题std::locale loc(boost::locale::generator().generate("ru_RU.cp1251"));。如果有人能解释代码有什么问题和/或我如何使用 boost 和 std 和 cp1251 语言环境进行类似的检查(isalpha),我将不胜感激。

4

1 回答 1

0

代替:

unsigned char debug501 = 'Б';

和:

char debug501 = 'Б';
于 2012-05-21T15:37:14.157 回答