gpt4 book ai didi

c++ - 如何解释C++字符串中的\u转义代码?

转载 作者:行者123 更新时间:2023-12-01 14:53:43 26 4
gpt4 key购买 nike

我想以编程方式在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;
}```



最佳答案

用于指示通用字符名称。从this源中,我们可以看到更详细的描述:

In character literals and native (non-raw) string literals, any character may be represented by a universal character name. Universal character names are formed by a prefix \U followed by an eight-digit Unicode code point, or by a prefix \u followed by a four digit Unicode code point. All eight or four digits, respectively, must be present to make a well-formed universal character name.



您得到的错误很可能是由于缺少变量值。我看不到在提供的上下文中 hex的声明位置。

关于c++ - 如何解释C++字符串中的\u转义代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59858657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com