[英]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.