Dealing with kanji characters in C++

烂漫一生 提交于 2019-12-06 06:27:17

I think you have two distinct issues here.

First, in the iteration, you try to read a key called _id, which isn't there (it should be id), so your int key is never assigned a value (and it's not initialized, that's why you get a weird number in your list view).

Second, you have to convert utf8 (stored in std::string) to ucs2, which is what a .NET String is made of. You can achieve that using the UTF8Encoding class (docs here) . So, instead of this:

String^ value = msclr::interop::marshal_as<System::String^>(iter->second);

you need something like this:

//make a byte array to hold the string chars
array<Byte>^ bytes = gcnew array<Byte>(iter->second.size());

//copy the string chars into the byte array
System::Runtime::InteropServices::Marshal::Copy(IntPtr(&iter->second[0]), bytes, 0, iter->second.size());

//get a string from the bytes, using UTF8Encoding
String^ value = System::Text::UTF8Encoding::UTF8->GetString(bytes);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!