为什么要在启动时执行std :: setlocale(lc_all,; c&quot')?

发布于 2025-01-28 15:54:50 字数 458 浏览 3 评论 0原文

cppreference.com

在程序启动期间,相当于std :: setlocale(lc_all,“ c”);在运行任何用户代码之前执行。

调用std :: setlocale(lc_all,“ c”);将当前的位置设置为“ c”:基本上是一个特殊的,简约的环境,其中字符串被视为简单的字符块很快。

显然,这会影响语言依赖性函数的工作原理(例如fprintftolower,...)。这是为什么?如果我想在程序中使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文