没有合适的用户定义的从 utility::string_t 到 std::string 的转换
no suitable user-defined conversion from utility::string_t to std::string
我正在使用 casablanca C++ Rest 库发出 HTTP 请求。
问题是这给出了一个 utility::string_t 字符串作为输出,我无法找到任何方法将其转换为经典 std::string。有什么想法吗?
client.request(methods::GET).then([](http_response response)
{
if(response.status_code() == status_codes::OK)
{
string_t s = response.extract_string().get();
}
});
如果您从 github 查看 C++ REST SDK 的文档,您会发现 typedef
C++ Rest SDK - utility Namespace Reference
typedef std::string string_t;
所以不需要转换。两者是相同的类型。
根据您编译的平台,utility::string_t
类型将被类型定义为 std::wstring
(在 Windows 上)或 std::string
(在 Linux/OSX).
要获得经典的 utf-8 std::string
,无论平台如何,请查看 utility::conversions::to_utf8string
。
在Windows Phone 8.1上有这个定义:
typedef std::wstring string_t;
我用过这个:
string_t toStringT = U("sample");
std::string fromStringT(toStringT.begin(), toStringT.end());
或:
std::string fromStringT(conversions::to_utf8string(toStringT));
我正在使用 casablanca C++ Rest 库发出 HTTP 请求。
问题是这给出了一个 utility::string_t 字符串作为输出,我无法找到任何方法将其转换为经典 std::string。有什么想法吗?
client.request(methods::GET).then([](http_response response)
{
if(response.status_code() == status_codes::OK)
{
string_t s = response.extract_string().get();
}
});
如果您从 github 查看 C++ REST SDK 的文档,您会发现 typedef
C++ Rest SDK - utility Namespace Reference
typedef std::string string_t;
所以不需要转换。两者是相同的类型。
根据您编译的平台,utility::string_t
类型将被类型定义为 std::wstring
(在 Windows 上)或 std::string
(在 Linux/OSX).
要获得经典的 utf-8 std::string
,无论平台如何,请查看 utility::conversions::to_utf8string
。
在Windows Phone 8.1上有这个定义:
typedef std::wstring string_t;
我用过这个:
string_t toStringT = U("sample");
std::string fromStringT(toStringT.begin(), toStringT.end());
或:
std::string fromStringT(conversions::to_utf8string(toStringT));