c++ - 使用 cpprestsdk 在 linux 上编译 wstring 的问题
问题描述
我有这样的代码
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");
^
解决方案
该项目wstring
用于windows,string
用于Linux。他们提供了一个类型string_t
和一个宏U
来帮助处理这个问题,您的代码需要更改才能在 Windows 和 Linux 上编译。
什么是实用程序::string_t 和“U”宏?C++ REST SDK 使用不同的字符串类型,具体取决于目标平台。例如,对于 Windows 平台,utility::string_t 是使用 UTF-16 的 std::wstring,在 Linux 上是使用 UTF-8 的 std::string。'U' 宏可用于创建平台类型的字符串文字。如果您使用的库导致与“U”宏发生冲突,例如 Boost.Iostreams,则可以通过在包含 C++ REST SDK 头文件之前定义宏“_TURN_OFF_PLATFORM_STRING”来关闭它。
请参阅此常见问题解答
一个典型的用法:
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"));
警告此项目的状态:
cpprestsdk 处于维护模式,我们不建议在新项目中使用它。我们将继续修复关键错误并解决安全问题。
推荐阅读
- android - 无论应用从属关系如何,都可以返回到上次打开的活动的正确意图标志
- if-statement - Google 表格中的嵌套 OR 语句 - 匹配评估错误
- selenium - 什么是 Firefox Gecko 相当于 Chrome 的 --disable-dev-shm-usage 标志
- vba - 如何优化一个 VBA 宏,它一次添加到多个阿拉伯语单词的链接
- batch-file - 通过批处理文件删除 wmic 结果中不需要的空格
- tsql - 根据 IF 语句将字符串转换为日期时间
- python - python 一个变量包含列表。如何组合成一个列表
- asp.net - 解决方案中未包含的 Visual Studio 编译文件
- uwp - UWP:如何使用 MediaCapture 为所有元数据拍照?
- c# - ASP>NET Core 2.1:app.Map 中的新类实例