gpt4 book ai didi

c++ - boost 区域设置格式百分比

转载 作者:行者123 更新时间:2023-11-27 23:05:24 25 4
gpt4 key购买 nike

我对 boost::locale::format 输出百分比有疑问。根据文档(http://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/localized_text_formatting.html):

Numbers and number manipulators

Here are the manipulators for number formatting:

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%

但是,以下输出“0.25”:

#include <string>
#include <iostream>
#include <boost/system/system_error.hpp>
#include <boost/locale.hpp>


int main(int argc, char** argv)
{
std::cout << boost::locale::as::percent << 0.25 <<std::endl;
}

我已经尝试通过 std::locale() 以及 boost::locale::generator 无济于事。

似乎我遗漏了一些明显的问题;有人可以暗示一下吗?

最佳答案

这对我有用:

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

关于c++ - boost 区域设置格式百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23868447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com