繁体   English   中英

使用boost :: locale时,std :: isalpha会抛出bad_cast

[英]std::isalpha throws bad_cast when using with boost::locale

我在Debian 7 GNU / Linux上使用boost :: locale(1.49)时遇到了一些麻烦(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;
}

它在使用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),我将感激不尽。

更换:

unsigned char debug501 = 'Б';

有:

char debug501 = 'Б';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM