簡體   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