我正在使用它boost::network::uri::encoded()
来编码我的请求 URL。
但是当我构建项目时,我看到了错误:
error C2039: "value": Is not a member of "boost::proto"
Run Code Online (Sandbox Code Playgroud)
其中有四个,他们的报道来自:
boost\proto\generate.hpp(239,20);
boost\proto\generate.hpp(239,53);
boost\proto\generate.hpp(248,20);
boost\proto\generate.hpp(248,53)
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码:
#include <iostream>
#include <string>
#include "boost/network/uri.hpp"
using std::string;
string EncodeURL(string str)
{
return boost::network::uri::encoded(str);
}
string DecodeURL(string str)
{
return boost::network::uri::decoded(str);
}
int main()
{
EncodeURL("https://test.com/a+a+a.html");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我安装boost
并cpp-netlib
使用了vcpkg。我的IDE是Visual Studio Professional 2019,操作系统是Windows 10 Professional Workstation x64(Ver.2004
)。
我想知道如何避免这些错误或使用其他方法对 UNICODE 兼容的 URL 进行编码。
我正在编写这样的模板函数:
template<typename T>
std::string EncodeData(int DataType, T Data, std::string ReadCommandID, std::string& ThisID);
Run Code Online (Sandbox Code Playgroud)
我想使用的类型T
是一些不同的结构,例如:
struct A
{
int A_data;
bool A_data_2;
// etc.......
};
struct B
{
double B_data;
char B_data_2;
// etc.......
};
Run Code Online (Sandbox Code Playgroud)
我希望函数可以根据不同的struct
传递来访问不同的成员变量T
,所以我写了这样的代码:
template<typename T>
std::string EncodeData(int DataType, T Data, std::string ReadCommandID, std::string& ThisID)
{
if(std::is_same<T, A>{})
{
// Do something with Data.A_data and Data.A_data_2
}
else if(std::is_same<T, B>{})
{
// Do something with Data.B_data and Data.B_data_2
}
// other code.
}
Run Code Online (Sandbox Code Playgroud)
并使用它: …