一点前景:我的任务需要将UTF-8 XML文件转换为UTF-16(当然还有正确的标题).所以我搜索了将UTF-8转换为UTF-16的常用方法,并发现应该使用来自的模板<codecvt>.
但现在当它被弃用时,我想知道执行相同任务的新常用方法是什么?
(根本不介意使用Boost,但除此之外我更喜欢尽可能靠近标准库.)
鉴于string foo,我已经写了关于如何使用's 将字符转换为小写的答案cctypetolower
transform(cbegin(foo), cend(foo), begin(foo), static_cast<int (*)(int)>(tolower))
Run Code Online (Sandbox Code Playgroud)
但我已经开始考虑 locale的tolower,这可以这样使用:
use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size()));
Run Code Online (Sandbox Code Playgroud)
tolower接受并返回一个int我认为只是一些过时的C东西的事实?如何使switch-case语句不区分大小写?说我做了这样的事情:
#include <stdio.h>
char choice;
int main ()
{
char choice;
printf("Will you choose A,B, or C?\n>");
scanf(" %c", &choice);
switch(choice)
{
case 'A':
printf("The First Letter of the Alphabet");
break;
case 'B':
printf("The Second Letter of the Alphabet");
break;
case 'C':
printf("The Third Letter of the Alphabet");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
它只会回应大写字母.如何让它回复小写字母?
当我在c ++中尝试使用非英语字符的tolower()时,它无法正常工作.我搜索了这个问题,但我发现了一些关于语言环境的内容,但我不确定最佳解决方案.
我的示例代码如下:
printf("%c ",tolower('Ü'));
Run Code Online (Sandbox Code Playgroud)