Problem of converting wchar_t to wstring

Hello, I encounter a problem of wchar_t to wstring. I tried as following, but I get a gibberish. How to convert the wchar_t to wstring properly.

Also I have anothe similar problem is how to convert a int to the ON_wString.

Many thanks.

            const wchar_t* key = user_att_strings[i].m_key;
            const wchar_t* value = user_att_strings[i].m_string_value;
            if (0 == key)
                key = L"";
            if (0 == value)
                value = L"";
            RhinoApp().Print(L"  <%ls> %ls.\n", key, value);
            wstring ss = key;
            wstring vv = value;
            //ss += vv;
            RhinoApp().Print(L" Key is %ls and vale is %ls.\n",key, value );
            RhinoApp().Print(L" Two Key is %ls and vale is %ls.\n", ss, vv);

Moved to Developer category

Hi @Qingxiang,

Does this help?

const wchar_t* psz = L"Hello Rhino!";
RhinoApp().Print("%ls\n", psz);

std::wstring wstr(psz);
RhinoApp().Print("%ls\n", wstr.c_str());

ON_wString onstr(psz);
RhinoApp().Print("%ls\n", static_cast<const wchar_t*>(onstr));

int value = 234;
onstr.Format(L"%d", value);
RhinoApp().Print("%ls\n", static_cast<const wchar_t*>(onstr));

– Dale

Yes, thanks for your warm-hearted help!