3

casablanca ライブラリを使用して json 値をシリアル化しています。

typedef std::wstring string_tこれを使用して std::string への変換を試み、wstring から string に変換しました。コンパイルは問題ありませんが、リターン行を実行するとプログラムがクラッシュします。

std::string getString()
{
    web::json::value cvalue;
    /* ----- code ----- */
    typedef std::wstring string_t;
    string_t outputString = cvalue.serialize();

    typedef std::codecvt_utf8<wchar_t> convert_type;
    std::wstring_convert<convert_type, wchar_t> converter;
    std::string converted_str = converter.to_bytes(outputString);

    return converted_str;
}

なぜこれがクラッシュしているのか理解できません。以下は、その関数を呼び出す行です。

std::string s = getString();

free(_Ptr)プログラムは、xdebug というファイルの行でブレーク ポイントをトリガーしました。ここで言っていることがよくわかりません。これがあなたのために物事を明確にするのに役立つことを願っています.

template<class _Ty>
    void __CLRCALL_OR_CDECL _DebugHeapDelete(_Ty *_Ptr)
    {   // delete from the debug CRT heap even if operator delete exists
    if (_Ptr != 0)
        {   // worth deleting
        _Ptr->~_Ty();
        // delete as _NORMAL_BLOCK, not _CRT_BLOCK, since we might have
        // facets allocated by normal new.
        free(_Ptr);
        }
    }

ありがとう!

4

1 に答える 1

14

C++ REST SDK にはutility::string_t、 utf8に変換する関数がありstd::stringます。utility::conversions::to_utf8string

参考資料

于 2016-02-02T08:12:07.667 に答える