ostringstream插入程序是否使用当前语言环境? [英] Does ostringstream inserter use current locale?
问题描述
要在没有科学符号的情况下将双精度转换为字符串,建议的方法是
To convert double to string without scientific notation, the suggested way is
std::ostringstream strStream;
strStream << std::fixed;
strStream << value;
std::string str = strStream.str();
我想将double转换为字符串,而无需使用任何分隔符,并且将Dot / Full-stop作为小数点,即忽略语言环境。
I want to convert double to string without any separator and Dot/Full-stop as the decimal point, i.e. ignoring locale.
来自 ostringstream 的描述, std :: fixed 和显示点,我无法确定
From description of ostringstream, std::fixed and showpoint, I couldn't determine
- 小数点是否在当前语言环境中?和
- str()根据语言环境返回的字符串中是否还会有其他分隔符(例如,成千上万个分组)?
如果按照当前语言环境设置,应采用什么方法覆盖-始终将点/句点作为小数点并且没有分组?
And if its as per current locale, what is the way to override so that - its always Dot/Full-stop as decimal point and there are no grouping?
推荐答案
是的,流的默认语言环境是构造时的当前全局语言环境(请参见 basic_ios :: init
放入您喜欢的参考中,然后检查流的类型是否正常运行-标准类都不做。)
Yes, the default locale for a stream is the current global locale at the time of construction (see description of basic_ios::init
in your favorite reference and then check that the kind of stream does not do otherwise -- none of the standard classes does).
更改语言环境,请使用 basic_ios :: imbue
,因此您可能要添加
To change the locale, use basic_ios::imbue
, thus you probably want to add
strStream.imbue(std::locale::classic());
。
这篇关于ostringstream插入程序是否使用当前语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!