![](/img/trans.png)
[英]Can boost::asio::yield_context set a std::error_code instead of boost::system::error_code?
[英]Cannot convert boost::asio::netdb::errors to std::error_code
我正在嘗試編譯此代碼(取自cpp-netlib文檔):
#include <boost/network/protocol/http/client.hpp>
#include <iostream>
int main(int argc, char *argv[]) {
using namespace boost::network;
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " [url]" << std::endl;
return 1;
}
http::client client;
http::client::request request(argv[1]);
request << header("Connection", "close");
http::client::response response = client.get(request);
std::cout << body(response) << std::endl;
return 0;
}
但是,它失敗並出現此錯誤:
Error C2446 ':': no conversion from 'boost::asio::error::netdb_errors' to 'const std::error_code'
我正在使用VS2015,cpp-netlib 0.12.0(最終)和Boost 1.55.0,我不知道是什么原因引起的。 有辦法解決嗎? 我一直在試圖讓這個庫工作幾天,但不幸的是,似乎總會出現一個新的錯誤。
在boost :: asio中,當你打算在回調/調用中使用錯誤代碼而不是std::error_code
,你應該使用boost::system::error_code
std::error_code
。
我不知道netlib在后台做了什么,但這可能是參考代碼中的錯誤,或者只是使用錯誤符號的舊版本代碼的證據。
我在OS X 10.11.4上使用了clang 7.3.0,cppnetlib 0.12.0,asio 1.10.6和10.60.0並且它可以工作。
我編譯了您使用clang++ -lcppnetlib-uri -lcppnetlib-client-connections -lssl -lcrypto -I/opt/local/include -L/opt/local/lib -std=c++11 test.cpp -o test
。
如果要啟用HTTPS支持,請確保在包含boost/network/protocol/http/client.hpp
之前添加#define BOOST_NETWORK_ENABLE_HTTPS
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.