Reputation: 1813
I'm currently writing a program in C++ which makes use of an API in C#. I need to pass this C# package a unicode symbol (which it will then draw).
The documentation, unfortunately, doesn't account for managed code. The C# example it gives is just:
String text = "\u2197\u2300\u21A7";
But when I try to do this in the C++:
String^ convertedText= gcnew String("\u2313");
I get the error:
"Character represented by universal-character-name "\u2313" cannot be represent in the current code page (1252)"
I'm not going quite sure how to go about fixing this. Does anyone have any suggestions?
Upvotes: 0
Views: 892
Reputation: 67080
C++/CLI is still C++ so "this string"
is not Unicode (which is default in C#). Just add L
prefix like this:
String^ convertedText = gcnew String(L"\u2313");
Or simply:
String^ convertedText = L"\u2313";
See this article on MSDN for C++ reference and this one for C# reference. In your case these representations are equivalent to your original C# string "\u2197\u2300\u21A7
:
L"\u2197\u2300\u21A7"
L"\x2197\x2300\x21A7"
L"↗⌀↧"
\u
can be used to specify Unicode surrogates and modifiers, for simple characters you can use \x
too.
Upvotes: 4