使用WriteConsoleW打印Unicode日语字符
Printing Unicode Japanese characters with WriteConsoleW
所以,我正在尝试打印一些日语字符。我尽了一切可能。我错过了什么?
#include <windows.h>
#include <string>
template<typename T>
void printW(const T* text) {
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), text, std::char_traits<T>::length(text), 0, 0);
}
template<typename T>
void print(const T* text) {
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), text, std::char_traits<T>::length(text), 0, 0);
}
int main()
{
//const char* text = "こんにちはn";
const wchar_t* textL = L"こんにちはn";
const char16_t* textu = u"こんにちはn";
const char32_t* textU = U"こんにちはn";
//printW(text);
printW(textL);
printW(textu);
printW(textU);
}
不需要WinAPI,而且您使用了错误的类型。
#include <iostream>
#include <string>
int main()
{
std::string text{u8"こんにちは"};
std::cout << text;
}
实例
如果您需要使用WinAPI,则需要最少的修改:
#include <windows.h>
#include <string>
template<typename T>
void print(const T* text) {
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), text, std::char_traits<T>::length(text), 0, 0);
}
int main()
{
auto text = u8"こんにちはn";
print(text);
}
免责声明:未在实际的windows机器上测试
相关文章:
- C++字符*缓冲区的大小
- HEX值到wchar_t字符(UTF-8)的转换
- 为什么 Serial.println(<char[]>);返回随机字符?
- 我的字符计数代码计算错误.为什么
- 字符串-C++后显示的随机字符
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 如何在C++中从字符串中分割字符
- 为什么msgrcv()将垃圾字符馈送到缓冲区
- 指向指向字符数组的指针数组的指针
- 如何用转义符替换字符串中的所有特殊字符
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 比较字符数组
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 如何在Windows日语系统中打印日语字符
- 使用WriteConsoleW打印Unicode日语字符
- 使用libharu在pdf中打印日语字符
- DCM4CHE无法显示日语字符
- 我如何在 1 字节普通字符串中存储日语字符?
- 日语系统中的字符转换不正确
- 如何检查日语或英语字符