Error C2679 in asyncrt_utils.h file while building C++ REST project

Jun 12, 2014 at 6:51 PM
Created a C++ console project in VS 2013 to access C++ REST SDK, however while trying to building this project I am getting a build error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string' in ...\packages\cpprestsdk.2.0.1\build\native\include\cpprest__asyncrt_utils.h__ file.

Build error is thrown in utility::string_t print_string function which is called when I am trying to add custom header to http_request object.
e.g. request.headers().add(header_names::authorization, auth);
What is the workaround for this issue?
Jun 13, 2014 at 9:16 PM
Hi UdayJ,

The problem is the http_headers::add(...) method works by using the stream operator << on an ostringstream_t (see the function print_string in asyncrt_utils.h at line 151). Which on Windows means it works with a 2 byte character UTF-16 string. In the future we might look at making a few places like this also work with UTF-8 strings on Windows.

To work around simply convert you std::string to a string_t with:
request.headers().add(header_names::authorization, ::utility::conversions::to_string_t(auth));
Thanks,
Steve
Marked as answer by UdayJ on 6/13/2014 at 9:58 PM
Jun 14, 2014 at 6:05 AM
Thanks Steve,

Using std::wstring instead of std::string solved my problem.