We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

GS::UniString can't support chinese

Anonymous
Not applicable
Hi.
When I want to use ACAPI_WriteReport ,I find that it can't print chinese.
Character garbled occurs. e.g:
ACAPI_WriteReport("你好,你好!"); it will show '??????????'.

My default char code is UTF8.How should I solve the problem?
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I recommend you to read this: https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp
To summarize it I quote the most relevant parts of the article:
String literals can have no prefix, or u8, L, u, and U prefixes to denote narrow character (single-byte or multi-byte), UTF-8, wide character (UCS-2 or UTF-16), UTF-16 and UTF-32 encodings...
    // String literals
    auto s0 =   "hello"; // const char*
    auto s1 = u8"hello"; // const char*, encoded as UTF-8
    auto s2 =  L"hello"; // const wchar_t*
    auto s3 =  u"hello"; // const char16_t*, encoded as UTF-16
    auto s4 =  U"hello"; // const char32_t*, encoded as UTF-32
So if you want to make sure that your string literal will be encoded as UTF-8, then you should use u8 perfix.
Try this:
ACAPI_WriteReport(u8"你好");

View solution in original post

2 REPLIES 2
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I recommend you to read this: https://docs.microsoft.com/en-us/cpp/cpp/string-and-character-literals-cpp
To summarize it I quote the most relevant parts of the article:
String literals can have no prefix, or u8, L, u, and U prefixes to denote narrow character (single-byte or multi-byte), UTF-8, wide character (UCS-2 or UTF-16), UTF-16 and UTF-32 encodings...
    // String literals
    auto s0 =   "hello"; // const char*
    auto s1 = u8"hello"; // const char*, encoded as UTF-8
    auto s2 =  L"hello"; // const wchar_t*
    auto s3 =  u"hello"; // const char16_t*, encoded as UTF-16
    auto s4 =  U"hello"; // const char32_t*, encoded as UTF-32
So if you want to make sure that your string literal will be encoded as UTF-8, then you should use u8 perfix.
Try this:
ACAPI_WriteReport(u8"你好");
Anonymous
Not applicable
Thanks.