// #include <QCoreApplication>
/*
* ModuleName: Main
* Description: Boost::asio::ip::tcp::resolver
* Author: hsw
* Date: 2020-04-11
*
*/
#include <iostream>
#include <boost/asio.hpp>
using boost::asio::ip::udp;
using boost::asio::ip::tcp;
int main(int argc, char *argv[])
{
boost::asio::io_context ioContext;
tcp::resolver ioResolver(ioContext);
tcp::resolver::query ioQuery(boost::asio::ip::tcp::v4(), "www.cnblogs.com", "https");
boost::system::error_code ec;
tcp::resolver::results_type ioResults = ioResolver.resolve(ioQuery, ec);
if(ec)
{
std::cout << "e = " << ec.message() << std::endl;
return -1;
}
std::cout << "ioResults Count = " << ioResults.size() << std::endl;
for(tcp::resolver::iterator iter = ioResults.begin(); iter != ioResults.end(); ++iter)
{
std::cout << "iter = " << iter->endpoint().address().to_string() << std::endl;
}
return 0;
}
来源:oschina
链接:https://my.oschina.net/u/4264209/blog/3230997