C++,从实用程序:string_t到标准::字符串的转换在返回时崩溃
C++, conversion from utility:string_t to std::string crashes on return
我正在使用卡萨布兰卡库来序列化json值。
我尝试使用 typedef std::wstring string_t
转换为 std::string,这将从 wstring 转换为字符串。它编译得很好,但程序在执行返回行时崩溃。
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
:
参考文档
相关文章:
- wcstombs_s(),转换字符串的长度
- 使用 CStringW/CStringA 和 CT2W/CT2A 转换字符串有什么区别?
- 无法转换字符串插入函数的参数
- 转换字符串向量:基于先前的值跳过元素
- 从中间器转换字符串不起作用,出了什么问题?
- 失败的证明转换字符串到枚举类
- 如何使用正则表达式和提升转换迭代器标记和转换 c 字符串
- 使用java jni时转换字符串类型
- 如何避免在转换字符串令牌流时重复istringstream构造
- 阿托伊未正确转换字符串
- C++,转换字符串,使连续下划线序列变为单个下划线
- 使用长算术转换字符串
- 转换字符串十进制数时的精度
- 将词法转换字符串提升为双精度
- 使用marshal_as函数转换字符串的性能
- C++不会从数据转换字符串
- 无论如何,在c++ /Qt中转换字符串到结构中的字段
- C++ 隐式类型转换字符串 -> int?
- 转换字符串到浮点数,c++实现
- 用于转换字符串大小写的函数