C++ 提升区域设置格式百分比

C++ 提升区域设置格式百分比,c++,boost,localization,formatting,locale,C++,Boost,Localization,Formatting,Locale,我对boost::locale::format输出的百分比有问题。 根据文件(): 数字和数字操纵器 以下是用于数字格式设置的操纵器: as::number -- format number according to local specifications, it takes into account as::percent -- format number as "percent" format. For example: cout << as::percen

我对boost::locale::format输出的百分比有问题。 根据文件():

数字和数字操纵器

以下是用于数字格式设置的操纵器:

as::number -- format number according to local specifications, it takes into account 
as::percent -- format number as "percent" format. For example:

        cout << as::percent << 0.25 <<endl;

Would create an output that may look like this:

    25%
as::number——根据本地规范格式化数字,它会考虑
as::percent——将数字格式化为“percent”格式。例如:
这对我来说很有效:

#include <boost/locale.hpp>
#include <iostream>

int main()
{
  boost::locale::generator gen;
  std::locale loc = gen("en_US.UTF-8");
  std::cout.imbue(loc);
  std::cout << boost::locale::as::percent << 0.25 << std::endl;
  return 0;
}
#包括
#包括
int main()
{
boost::locale::gen生成器;
std::LOCE loc=gen(“en_US.UTF-8”);
标准:电流注入(loc);
std::cout这对我很有效:

#include <boost/locale.hpp>
#include <iostream>

int main()
{
  boost::locale::generator gen;
  std::locale loc = gen("en_US.UTF-8");
  std::cout.imbue(loc);
  std::cout << boost::locale::as::percent << 0.25 << std::endl;
  return 0;
}
#包括
#包括
int main()
{
boost::locale::gen生成器;
std::LOCE loc=gen(“en_US.UTF-8”);
标准:电流注入(loc);

std::coutBoost.Locale使用4个后端(ICU、posix、winapi、std),但只有ICU后端具有百分比功能,这意味着您使用的库未使用ICU库编译


您可以在表中看到哪个功能可以与哪个后端一起使用。

Boost.Locale使用4个后端(ICU、posix、winapi、std),但只有ICU后端具有百分比功能,这意味着您使用的库没有使用ICU库编译


您可以在表中看到哪个功能可以与哪个后端一起使用。

shenangians。这为我输出0.25…您的默认区域设置是什么?可能是您的系统区域设置已损坏。
locale
print是什么?mhh它正在打印英语和美国。1252。我应该添加这是在Win7 SP1上。我在两台机器上进行了尝试。您是什么r boost版本?我使用的是v1.53。什么是
1252
应该是什么?它应该是
Windows-1252
。如果我使用
std::locale loc=gen(“English_-United.Windows-1252”);
它打印
25%
。Mhhh…我在1.54上。生成“English_-United.Windows-1252”将仍然为我输出0.25和您发布的代码…我可以看到,当我通过boost时,它在类中设置了百分比方面标志:/I无法强制它打印任何带有任何选项的百分比符号!s诡计。这为我输出0.25…您的默认区域设置是什么?它可能是您的系统区域设置腐败。
locale
打印什么?mhh它打印的是英语和美国。1252。我应该加上这是在Win7 SP1上。我在两台机器上试过。你的增强版本是什么?我使用的是v1.53。
1252
应该是什么?应该是
Windows-1252
。如果我使用
std::locale=gen(“English_United States.Windows-1252”);
它打印
25%
.mhh…我在1.54上。正在生成“English_United States.Windows-1252”"将仍然为我输出0.25和您发布的代码…我可以看到,当我通过boost时,它在类中设置了百分比方面标志:/I无法强制它打印任何带有任何选项的百分比符号!谢谢!这确实是导致它的原因;我仔细检查了!谢谢!这确实是导致它的原因;我仔细检查!