簡體   English   中英

如何解釋 C++ 字符串中的 \\u 轉義碼?

[英]How do I interpret a \u escape code in a C++ string?

我想在 C++ 中以編程方式構建一個 unicode 字形列表,但我找不到解決編譯器錯誤\\u used with no following hex digits

#include <iostream>
#include <sstream>

using namespace std;

int main() 
{
    int unicode = 0x2200;
    stringstream result;
    for (int i = 0; i<0x0F; ++i)
    {
    unicode += i ;
    result << "\u" << hex << unicode << "\n";
    };

    cout << result.str();

    return 0;
}```



用於表示通用字符名稱。 這個來源我們可以看到更詳細的描述:

在字符文字和本機(非原始)字符串文字中,任何字符都可以由通用字符名稱表示。 通用字符名稱由前綴 \\U 后跟八位 Unicode 代碼點或前綴 \\u 后跟四位 Unicode 代碼點組成。 必須分別存在所有八位或四位數字才能形成格式良好的通用字符名稱。

您得到的錯誤可能是由於缺少變量值。 我沒有看到在提供的上下文中在哪里聲明了hex

感謝您的回答。

我確實找到了一次增加一個字形的方法(我指的是這個列表https://unicode-table.com/en/#arrows

#include <iostream>
#include <sstream>

using namespace std;

int main() 
{
    std::string data = "\u2200";
    data[2] += 1;

    cout << "Starting glyph 2200-> \u2200 \n" 
    << "Expected glyph 2201-> \u2201 \n"
    << "Resulting glyph is-> " << data << '\n';

    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM