I am using the casablanca C++ Rest library to make HTTP requests.
The problem is that this gives a utility::string_t string as output and I can't quite find any way to convert this to a classic std::string. Any ideas?
client.request(methods::GET).then([](http_response response)
{
if(response.status_code() == status_codes::OK)
{
string_t s = response.extract_string().get();
}
});
If you see the documentation for C++ REST SDK from github, you'll find a typedef
C++ Rest SDK - utility Namespace Reference
typedef std::string string_t;
So no need to convert it. Both are same types.
Depending on what platform you are compiling for, the utility::string_t
type will be typedef'd to either std::wstring
(on Windows) or std::string
(on Linux/OSX).
To get a classic utf-8 std::string
regardless of platform, take a look at utility::conversions::to_utf8string
.
On Windows Phone 8.1 there is this define:
typedef std::wstring string_t;
I used this:
string_t toStringT = U("sample");
std::string fromStringT(toStringT.begin(), toStringT.end());
or:
std::string fromStringT(conversions::to_utf8string(toStringT));
来源:https://stackoverflow.com/questions/31264974/no-suitable-user-defined-conversion-from-utilitystring-t-to-stdstring