有没有办法指定 const unichar 带引号的字符串?
使用 xcode,我尝试通过执行以下操作将 const c 字符串放入 unichar 数组中:
const unichar *str = "Test String";
但“测试字符串”的类型为 (const char *) 并产生编译器错误。有没有办法指定 unichar 类型的“测试字符串”?
我希望有这样的事情:
const unichar *str = U"Test String";
所以所有的工作都是在编译期间完成的。
Using xcode, I'm trying to get a const c string into a unichar array by doing the following:
const unichar *str = "Test String";
but the "Test String" is typed to be (const char *) and produces compiler errors. Is there way to specify a "Test String" that is of type unichar?
I was hoping for somethig like:
const unichar *str = U"Test String";
so all the work was done during compile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在项目设置中的“Apple LLVM 编译器”下为 C++ Language Dialect 选择了 C++11,则可以使用新的 C++ 字符类型 char16_t - 它的大小与 unichar 类型相同。然后,您可以在如下代码中初始化字符串文字:
const char16_t* str = u"My UTF-16 string";
If you chose C++11 for C++ Language Dialect under "Apple LLVM compiler" in your project settings, you may use the new C++ character type char16_t - it's the same size like the unichar type. Then you may initialize string literals in code like that:
const char16_t* str = u"My UTF-16 string";
也许 const unichar *str = L"Test String"; 适合您。
Perhaps
const unichar *str = L"Test String";
would work for you.据我所知,没有办法使用这样的字符串来做到这一点。
你可以这样做
const unichar string[] = {'u','n','i','c','o','d','e'};
但除此之外,我不知道。
但我可能是错的,我在 C++ 的这一方面还没有做太多:)
as far as i know there is no way to do it using a string like that.
You can do it like this
const unichar string[] = {'u','n','i','c','o','d','e'};
But aside from that, i don't know.
But i could be wrong i haven't done very much with this side of c++ :)