zanllp / sion

A single-header, cross-platform C++ library for making asynchronous HTTP(s) Requests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

windows vs2022编译报错

Shaw666 opened this issue · comments

我定义了unicode编码
sion.hpp(667,1): error C2664: “INT InetPtonW(INT,PCWSTR,PVOID)”: 无法将参数 2 从“const _Elem *”转换为“PCWSTR”

`
...
auto target_ip =
enable_proxy_
? (proxy_.host.HasLetter() ? GetIpByHost(proxy_.host) : proxy_.host)
: ip_;
#ifdef _WIN32
checkstd::invalid_argument(
(InetPton(AF_INET, target_ip.c_str(), &sa) != -1), "地址转换错误");//报错,详情如上
#else
checkstd::invalid_argument(
(inet_pton(AF_INET, target_ip.c_str(), &sa) != -1), "地址转换错误");
#endif
...

`

unicode字符集当前确实不支持,这边新项目直接在linux或者mac下写了就没用到
等我这周末有时间来看下怎么改,有兴趣也可以自己尝试修改下提个pr

确实,代码中的中文也会全部报错,修改为utf-8-with bom可以解决这部分,但是另外String类会报错,因为unicode会引入一堆wchar*,

各位可以考虑对class String增加如下修改,vs2022 unicode将编译通过使用:
... String(WCHAR* arg) { std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; this->assign(converter.to_bytes(arg)); } ...

不过针对使用到的转换标准函数将会有警告:
[build] E:\test\test_sion\sion.h(62,31): warning C4996: 'std::codecvt_utf8<wchar_t,1114111,(std::codecvt_mode)0>': warning STL4017: std::wbuffer_convert, std::wstring_convert, and the header (containing std::codecvt_mode, std::codecvt_utf8, std::codecvt_utf16, and std::codecvt_utf8_utf16) are deprecated in C++17. (The std::codecvt class template is NOT deprecated.) The C++ Standard doesn't provide equivalent non-deprecated functionality; consider using MultiByteToWideChar() and WideCharToMultiByte() from <Windows.h> instead. You can define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
不过可以选择忽略或者自行按提示解决

F9B4FC44B67F85A33E98623E1A5C9C53
强制sion内部只使用char解决了这个问题,在最新的master。