Floppy β Studio
Floppy β Studio

C++控制台输出中文乱码的解决办法

剧情:我在使用我最喜欢用的http库(yhirose/cpp-httplib: A C++ header-only HTTP/HTTPS server and client library (github.com))抓取我的网站首页时中文出现乱码

然后我在Github上发了个Issue(Garbled characters when outputting some text using cout · Issue #1227 · yhirose/cpp-httplib (github.com))

收到的回复:

@ifloppy, this issue is out of the scope of this library. You are responsible to appropriately convert the text in the response to fit your environment. Sorry that I can't give you any more help.

翻译:软盘君,这个Issue时在这个库的范围中。你对适当地转换(HTTP请求的)回应到适合你的环境的(编码)要负责。抱歉,我们不能给你提供更多的帮助。

如果我是这个库的贡献者,我当然也会这么说。因为这个问题似乎很好解决。

经过一番Google,面向CSDN的编程,看到了这个:【VS输出UTF8】 C++ 控制台程序中输出UTF8字符乱码问题解决方法_bandaoyu的博客-CSDN博客_printf utf8

好家伙,我以前就不知道Windows的控制台还有这么个功能。但是用系统自带的又会输出一些额外的内容

于是,面向stack overflow的编程 c++ - Output unicode strings in Windows console app - Stack Overflow

只需要在一开始执行如下内容:

发表回复

textsms
account_circle
email


Floppy β Studio

C++控制台输出中文乱码的解决办法
剧情:我在使用我最喜欢用的http库(yhirose/cpp-httplib: A C++ header-only HTTP/HTTPS server and client library (github.com))抓取我的网站首页时中文出现乱码 然后我在Github…
扫描二维码继续阅读
2022-03-25