我有以下代码,它使用我正在编写的库中的 Unicode 字符串类:
#include <cstdio>
#include "ucpp"
main() {
ustring a = "test";
ustring b = "ing";
ustring c = "- -";
ustring d;
d = "cafe\xcc\x81";
printf("%s\n", (a + b + c[1] + d).encode());
}
ustring 类实例的 encode 方法将内部 Unicode 转换为 UTF-8 char *。但是,因为我无权访问 char 类定义,所以我不确定如何定义隐式类型转换(这样我就不必在与 printf 等一起使用时手动调用编码)。