使用 cpprestsdk 在 linux 上编译 wstring 时出现问题

problem with compiling wstring on linux with cpprestsdk

我有这样的代码

using namespace web;                
using namespace http;   

const http_response& response = /*valid assignment*/
http_headers::const_iterator it = response.headers().find(L"SomeKey");
if (it != response.headers().end())
    {
        //doing something
    }

response 有有效数据。 它正在使用 windows 进行编译。我想用 g++ 在 Linux 中编译相同的片段。我该如何处理? 我需要添加一些编译标志吗? 我得到这样的错误:

 error: no matching function for call to ‘web::http::http_headers::find(const wchar_t [17]) const’
   http_headers::const_iterator it = response.headers().find(L"SomeKey");
                                                                       ^

该项目对 windows 使用 wstring,对 Linux 使用 string。他们提供了一个类型 string_t 和一个宏 U 来帮助处理这个问题,您的代码需要更改为在 Windows 和 Linux.[=20 上编译=]

What is utility::string_t and the 'U' macro? The C++ REST SDK uses a different string type dependent on the platform being targeted. For example for the Windows platforms utility::string_t is std::wstring using UTF-16, on Linux std::string using UTF-8. The 'U' macro can be used to create a string literal of the platform type. If you are using a library causing conflicts with the 'U' macro, for example Boost.Iostreams it can be turned off by defining the macro '_TURN_OFF_PLATFORM_STRING' before including the C++ REST SDK header files.

看到这个FAQ

典型用法:

static const utility::string_t wl_birthday = U("wl.birthday");
static const utility::string_t wl_basic = U("wl.basic");

对于您的代码:

http_headers::const_iterator it = response.headers().find(U("SomeKey"));

有关此项目的 status 的警告:

cpprestsdk is in maintenance mode and we do not recommend its use in new projects. We will continue to fix critical bugs and address security issues.