There is no suitable user conversion from utility :: string_t to std :: string

I am using casablanca C ++ Rest library to create HTTP requests.

The problem is that this gives the :: string_t string utility as output, and I cannot find a way to convert it to the 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(); } }); 
+5
source share
3 answers

If you see the documentation for the C ++ REST SDK from github, you will find typedef

C ++ Rest SDK - reference reference to namespace

 typedef std::string string_t; 

So there is no need to convert it. Both are the same.

+2
source

Depending on which platform you are compiling, the type of utility::string_t will be typedef'd for std::wstring (on Windows) or std::string (on Linux / OSX).

To get the classic utf-8 std::string regardless of platform, see utility::conversions::to_utf8string .

reference documentation

+8
source

On Windows Phone 8.1, this definition is:

 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)); 
+2
source

All Articles