为什么要在启动时执行std :: setlocale(lc_all,; c&quot')?
cppreference.com 说:
在程序启动期间,相当于std :: setlocale(lc_all,“ c”);在运行任何用户代码之前执行。
调用std :: setlocale(lc_all,“ c”);
将当前的位置设置为“ c”:基本上是一个特殊的,简约的环境,其中字符串被视为简单的字符块很快。
显然,这会影响语言依赖性函数的工作原理(例如fprintf
,tolower
,...)。这是为什么?如果我想在程序中使用UTF-8字符串,我应该将其恢复到其他地方吗?
Cppreference.com says:
During program startup, the equivalent of std::setlocale(LC_ALL, "C"); is executed before any user code is run.
Calling std::setlocale(LC_ALL, "C");
sets the current locale to "C": basically a special, minimalistic locale where strings are seen as simple chunk of bytes, no knowledge of characters and so on.
This obviously affects how locale-dependent functions work (e.g. fprintf
, tolower
, ...). Why is that? Should I revert the locale to something else if I want to work with UTF-8 strings in my program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论