C++,从 utility:string_t 到 std::string 的转换在 return 上崩溃
C++, conversion from utility:string_t to std::string crashes on return
我正在使用 casablanca 库序列化 json 个值。
我尝试使用 typedef std::wstring string_t
和 this to convert from wstring to string 转换为 std::string。编译正常,但程序在执行 return 行时崩溃。
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();
程序在名为 xdebug 的文件中的第 free(_Ptr)
行处触发了一个断点。我真的不明白这里说的是什么。希望这有助于为您澄清事情。
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);
}
}
谢谢!
在 C++ REST SDK 中有一个将 utility::string_t
转换为 utf8 std::string
的函数:utility::conversions::to_utf8string
我正在使用 casablanca 库序列化 json 个值。
我尝试使用 typedef std::wstring string_t
和 this to convert from wstring to string 转换为 std::string。编译正常,但程序在执行 return 行时崩溃。
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();
程序在名为 xdebug 的文件中的第 free(_Ptr)
行处触发了一个断点。我真的不明白这里说的是什么。希望这有助于为您澄清事情。
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);
}
}
谢谢!
在 C++ REST SDK 中有一个将 utility::string_t
转换为 utf8 std::string
的函数:utility::conversions::to_utf8string