[英]How to create a 0x appended hex string from a hex string for each byte of hex characters in C++?
[英]How to output Unicode characters from hex string in C++?
我有一個名為str
其中包含十六進制代碼265A
,我想將其輸出為 Unicode 字符,它應該是黑棋王。
所以這些是我已經嘗試過的方法:
std::string str = "\u" + str;
std::cout << str;
但這給了我錯誤
error: incomplete universal character name \u
正在做
std::cout << "\u" << str;
也沒有工作,出於同樣的原因。
所以我嘗試像這樣使用
wchar_t
:
wchar_t wc = strtol(str.c_str(), NULL, 16);
std::wcout << wc;
但這只是沒有輸出任何東西。
所以我真的不知道還能做什么。
你的strtol
方法是正確的。 以下測試程序測試您可以A
這種方式創建A
:
#include <string>
#include <cstdlib>
#include <iostream>
int main()
{
const std::string str = "41";
wchar_t wc = std::strtol(str.c_str(), NULL, 16);
std::wcout << wc << std::endl;
}
您可能在輸出方面遇到問題,或者您系統的wchar_t
是某種非 Unicode 類型 - 您可以用類似的東西來證明這一點
std::wcout << wchar_t(65) << wchar_t(0x265A) << std::endl;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.