相关疑难解决方法(0)

已弃用标头<codecvt>替换

一点前景:我的任务需要将UTF-8 XML文件转换为UTF-16(当然还有正确的标题).所以我搜索了将UTF-8转换为UTF-16的常用方法,并发现应该使用来自的模板<codecvt>.

但现在当它被弃用时,我想知道执行相同任务的新常用方法是什么?

(根本不介意使用Boost,但除此之外我更喜欢尽可能靠近标准库.)

c++ utf-8 utf-16 codecvt c++17

54
推荐指数
4
解决办法
1万
查看次数

C++中的哪个版本?

鉴于string foo,我已经写了关于如何使用's 将字符转换为小写的答案cctypetolower

transform(cbegin(foo), cend(foo), begin(foo), static_cast<int (*)(int)>(tolower))
Run Code Online (Sandbox Code Playgroud)

但我已经开始考虑 localetolower,这可以这样使用:

use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size()));
Run Code Online (Sandbox Code Playgroud)
  • 是否有理由偏好其中一个而不是另一个?
  • 它们的功能是否完全不同?
  • 我的意思是tolower接受并返回一个int我认为只是一些过时的C东西的事实?

c++ string locale ctype tolower

20
推荐指数
2
解决办法
1301
查看次数

如何使switch-case语句不区分大小写?

如何使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

5
推荐指数
3
解决办法
1万
查看次数

tolower()不适用于c ++中的Ü,Ö

当我在c ++中尝试使用非英语字符的tolower()时,它无法正常工作.我搜索了这个问题,但我发现了一些关于语言环境的内容,但我不确定最佳解决方案.

我的示例代码如下:

printf("%c ",tolower('Ü'));
Run Code Online (Sandbox Code Playgroud)

c++ tolower

4
推荐指数
1
解决办法
970
查看次数

标签 统计

c++ ×3

tolower ×2

c ×1

c++17 ×1

codecvt ×1

ctype ×1

locale ×1

string ×1

utf-16 ×1

utf-8 ×1