简体   繁体   English

如何对非ascii字符使用tolower函数

[英]How to use tolower function for non-ascii characters

I am trying to apply lower function on non-ASCII characters. 我试图在非ASCII字符上应用较低的功能。 Following code doesn't work in Linux(Ubuntu) environment but works in windows. 以下代码在Linux(Ubuntu)环境中不起作用,但在Windows中工作。

int main() {
        std:string data="ŽŠ";
        std::transform(data.begin(), data.end(), data.begin(), ::tolower);
        cout<< data << endl;
        return 0;
}

I tried installing language packs but did not work.Can someone help me what am i missing in this code? 我尝试安装语言包但没有工作。有人可以帮我解释这段代码中缺少的是什么吗?

::tolower() relies in the current locale set in the C library. ::tolower()依赖于C库中设置的当前语言环境。 The default "C" locale is only guaranteed to handle ASCII characters. 默认的"C"语言环境仅保证处理ASCII字符。 Microsoft is likely using a different default locale that matches the user's current locale. Microsoft可能使用与用户当前区域设置匹配的其他默认区域设置。 That would explain why the code is able to work on Windows. 这可以解释为什么代码能够在Windows上运行。

Use ::setlocale() to set the desired locale for ::tolower() to use. 使用::setlocale()::tolower()设置所需的语言环境。 Otherwise, use a portable Unicode library, such as ICU . 否则,请使用可移植的Unicode库,例如ICU

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

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