简体   繁体   English

std::cout.imbue() 多次调用

[英]std::cout.imbue() multiple call

Compiler : Visual Studio 2019(C++20, latest)编译器:Visual Studio 2019(C++20,最新)
I have a question about std::locale我有一个关于 std::locale 的问题
Is it impossible to call std::cout.imbue multiple?不能多次调用 std::cout.imbue 吗?
Why is it impossible?为什么不可能?

When I ran below code.. I can see two of question mark(??) after second imbue function call..当我运行下面的代码时.. 我可以在第二次 imbue 函数调用后看到两个问号 (??) ..

#include <iomanip>
#include <iostream>
#include <locale>

int main()
{
    auto loc = std::locale("de_DE.utf8");
    std::cout.imbue(loc);
    std::cout << "locale_name = " << std::cout.getloc().name() << std::endl;
    std::cout << 100.50 << std::endl;
    std::cout << std::showbase << std::put_money(1050) << std::endl;

    std::cout.imbue(loc);   // no output below
    std::cout << "locale_name = " << std::cout.getloc().name() << std::endl;
    std::cout << 100.50 << std::endl;
    std::cout << std::showbase << std::put_money(1050) << std::endl;
}

Here is output这是输出
locale_name = de_DE.utf8 locale_name = de_DE.utf8
100,5 100,5
10,50 ?? 10,50 ??

There is no such restriction, and the output for me is:没有这样的限制,我的输出是:

locale_name = de_DE.utf8
100,5
10,50 €
locale_name = de_DE.utf8
100,5
10,50 €

Note that the Euro symbol may be replaced by weird stuff like ??请注意,欧元符号可能会替换为奇怪的东西,例如?? if your output terminal is not properly configured to show UTF-8 characters, or if that glyph is missing in your terminal's font.如果您的输出终端未正确配置为显示 UTF-8 字符,或者您的终端字体中缺少该字形。

For example, from memory, Visual Studio's output console either does not support Unicode or always decodes as UTF-16.例如,根据内存,Visual Studio 的输出控制台要么不支持 Unicode,要么总是解码为 UTF-16。 One of the two.两者之一。 Probably the latter.大概是后者。

Besides that, if you get output different from the above, that would be an interesting standard library bug in your implementation.除此之外,如果您得到与上述不同的输出,那将是您的实现中一个有趣的标准库错误。

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

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