【发布时间】:2020-03-05 11:00:05
【问题描述】:
我使用的是 CLang 8.0 并给出了这个代码示例:
#include <locale>
#include <sstream>
#include <iostream>
struct slash : std::numpunct<char> {
char do_decimal_point() const { return '/'; } // separate with slash
};
int main()
{
std::ostringstream oss;
auto slash_locale = std::locale(std::cout.getloc(), new slash);
std::locale::global( slash_locale );
oss << 4.5;
std::cout << oss.str();
}
我得到的是“4.5”。我的问题是:这种忽略标准中写的语言环境的行为吗?因为我的一位同事正在使用 XCode 并声明正在打印“4/5”。我想了解它是否应该由实现定义,或者如果我的同事陈述真相,是否违反了标准。
【问题讨论】:
标签: c++ localization c++-standard-library