获取当前在C++中设置的全局区域设置
Get the global locale that is currently set in C++?
在C++中,我可以设置当前区域设置,如下所示:
std::locale::global(std::locale(name))
但是,我如何获得当前的全局区域设置?
在我的代码中,我需要获取当前区域设置,将其保存到tmp var中,将全局区域设置为其他区域设置,输出一些内容,然后将其设置回以前的区域设置。
如果调用std::locale
的默认构造函数,就会得到它。
std::locale the_global_locale; // <-- automatically correct to std::locale::global
// or a copy of std::locale::classic
更多信息请点击此处:http://en.cppreference.com/w/cpp/locale/locale/locale
它的返回值是旧的区域设置,所以只使用它。
locale l = locale::global(locale(name));
//do some stuff here
locale::global(l);
编辑:可能有用:http://en.cppreference.com/w/cpp/locale/locale/global
正如ipc所说,std::locale的默认构造函数为您提供了当前全局区域设置的副本,但为什么您需要缓存然后重置全局区域设置?
使用区域设置的C++例程通常可以使用您指定的C++区域设置对象,因此您根本不必处理全局区域设置。使用区域设置对象应该优先于使用C++全局区域设置。
相关文章:
- Arduino 模块化编程与全局和设置
- 如何为lua_State设置全局C++指针
- 如何在C++项目中设置全局 #define?
- C vs 2017设置全局变量 - 程序仅在调试中使用断点
- C++ 给出编译器错误,将一个(静态)常量全局变量设置为另一个静态常量变量
- 使用 API 而不是全局配置文件设置 OSM 配置选项
- Codelite不使用全局编译设置或项目编译设置
- 设置全局指针
- 存储在全局变量中的函数指针在进入函数时设置为 0,并在退出函数时返回到以前的状态
- 确定函数是否是在没有设置全局变量的情况下调用的
- 如何设置全局容器(C++03)
- 将大小设置为结构类型全局变量时发生编译器错误
- 如何在后台线程上正确设置全局鼠标挂钩
- 从存储在 SPIFFS 中的变量中设置全局对象 ESP8266.
- 在hlsl着色器中设置全局参数的正确方法是什么
- c++lua设置全局变量时出错
- 设置全局区域设置时内存泄漏
- 问:当我有一堆小部件时,如何设置全局mouseReleaseEvent
- 正在尝试使用Redispp在类中设置全局Redis连接
- visualstudio2013-如何在C++中的void中设置全局int