C++在控制台打印宽字符
程序运行无报错,但是宽字符无法显示,应该怎样调整终端设置和代码呢#include <iostream>
int main() {
// This would be an error - narrowing conversion of '14851492' from 'int' to 'char'
// char heart{'❤'};
// char word {'你'};
wchar_t heart{L'❤'};
wchar_t word{L'你'};
std::wcout << L"你好 " << heart << word;
} 要么你转换,要么你设置一下代码页 SetConsoleOutputCP(65001) bester 发表于 2024-6-13 11:42
要么你转换,要么你设置一下代码页 SetConsoleOutputCP(65001)
设置代码页也不行,窗口空白。代码如下:
#include <iostream>
#include <windows.h>
int main() {
// This would be an error - narrowing conversion of '14851492' from 'int' to 'char'
// char heart{'❤'};
// char word {'你'};
SetConsoleOutputCP(65001);
wchar_t heart{L'❤'};
wchar_t word{L'你'};
std::wcout << L"你好 " << heart << word;
} locale loc("chs"); wcout.imbue(loc); '❤' 这种写法没见过 go4399 发表于 2024-6-13 12:45
'❤' 这种写法没见过
这是我粘贴代码的时候,论坛自动转换了字符。把它当成一个普通的 unicode 字符即可。实际上它是一颗红心。 菜鸟小白 发表于 2024-6-13 12:21
不行
https://a1.boltp.com/2024/06/13/666a8b34ecd09.webp mt324 发表于 2024-6-13 12:01
locale loc("chs"); wcout.imbue(loc);
不行
https://a1.boltp.com/2024/06/13/666a8b95468b5.webp #include <Windows.h>
#include <iostream>
int main() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleOutputCP(CP_UTF8);
SetConsoleMode(hConsole, ENABLE_VIRTUAL_TERMINAL_PROCESSING);
WriteConsoleW(hConsole, L"这是一个笑脸:😊\n", 11, NULL, NULL);
return 0;
}
页:
[1]
2