简体   繁体   English

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

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

I have some troubles with using boost::locale (1.49) on Debian 7 GNU/Linux (version of GCC is 4.6.3-1). 我在Debian 7 GNU / Linux上使用boost :: locale(1.49)时遇到了一些麻烦(GCC的版本是4.6.3-1)。 The code is saved in cp1251. 代码保存在cp1251中。 Using functions like "isalpha" (or "boost::algorithm::is_alpha") ends up with exception (bad_cast). 使用像“isalpha”(或“boost :: algorithm :: is_alpha”)这样的函数会以异常(bad_cast)结束。 Looks like that there's no proper facet for this check. 看起来这张支票没有合适的方面。 Here's the code: 这是代码:

#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;
}

It runs with no exception on Windows 7 with Visual Studio 2008. However, there's still one trouble: "debug500" is set to false in this case. 它在使用Visual Studio 2008的Windows 7上毫无例外地运行。但是,仍然存在一个问题:在这种情况下,“debug500”设置为false。 It works fine only when locale is generated like this: std::locale loc(".1251") . 只有在生成区域设置时才能正常工作: std::locale loc(".1251") But the same issue appears when locale is generated by boost: std::locale loc(boost::locale::generator().generate("ru_RU.cp1251")); 但是当locale由boost生成时会出现同样的问题: std::locale loc(boost::locale::generator().generate("ru_RU.cp1251")); . I would be thankful if someone could explain what's wrong with the code and/or how I can make a similar check (isalpha) using boost and std with cp1251 locale. 如果有人能解释代码的错误和/或我如何使用boost和std与cp1251语言环境进行类似的检查(isalpha),我将感激不尽。

Replace: 更换:

unsigned char debug501 = 'Б';

with: 有:

char debug501 = 'Б';

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

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