这段简单的代码和最新的clang ++让我度过了一段难忘的时光
#include <stdio.h>
#include <string>
using std::u16string;
int main ( int argc, char** argv )
{
u16string s16 = u"?????????";
return EXIT_SUCCESS;
}
Ben-iMac:Desktop Ben$ clang++ -std=c++0x -stdlib=libc++ main.cpp -o main
main.cpp:15:21: error: use of undeclared identifier 'u'
u16string s16 = u"?????????"
Run Code Online (Sandbox Code Playgroud)
来自llvm.org或Apple的clang 3.0 的最新发布的clang,v2.9版本不支持Unicode字符串文字.从主干源顶部构建的最新可用版本确实支持Unicode字符串文字.
clang的下一个llvm.org版本(即3.0)将支持Unicode字符串文字语法,但不支持ASCII以外的任何源文件编码.因此,即使使用llvm.org版本,您也无法在源代码中输入这些字符,并将它们转换为UTF-16编码的字符串值.相反,你将不得不使用\ u转义.同样,trunk的顶部确实支持UTF-8源代码,但它没有及时投入到目前正在测试的llvm.org 3.0版本中.之后的下一个版本(在6个月左右)应该更好地支持UTF-8源代码(但不支持其他源代码).
编辑:clang的Xcode 4.3版本确实具有这些功能.
编辑:现在LLVM.org的3.1版本有它们
所以clang现在完全支持以下内容:
#include <string>
int main() {
std::u16string a = u"?"; // UTF-8 source is transformed into UTF-16 literal
std::u32string b = U"?"; // UTF-8 source is transformed into UTF-32 literal
}
Run Code Online (Sandbox Code Playgroud)
事实证明,标准实际上并不需要对iostreams库中的char16_t和char32_t提供太多支持,因此您可能必须转换为另一种字符串类型才能充分利用它.至少需要在这些和更有用的std :: string之间进行转换的能力(虽然设置起来不太方便......).