gpt4 book ai didi

c++ - 无法将 boost::asio::netdb::errors 转换为 std::error_code

转载 作者:太空宇宙 更新时间:2023-11-04 13:16:54 24 4
gpt4 key购买 nike

我正在尝试编译此代码(取自 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::,你就应该使用 boost::system::error_code error_code.

我不知道 netlib 在后台做什么,但这可能是引用代码中存在错误的证据,或者只是旧版本代码使用了错误的符号。

关于c++ - 无法将 boost::asio::netdb::errors 转换为 std::error_code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36990461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com