boost.asio学习-----reslover 域名解析

时间:2024-12-27 23:36:50

将域名解析为ip地址并输出:

 #include "stdafx.h"
#include "boost/asio.hpp"
#include <boost/lexical_cast.hpp> using namespace std;
using namespace boost::asio; int _tmain(int argc, _TCHAR* argv[])
{
boost::asio::io_service ios;
//创建resolver对象
ip::tcp::resolver slv(ios);
//创建query对象
ip::tcp::resolver::query qry("www.google.com", boost::lexical_cast<string>());
//使用resolve迭代端点
ip::tcp::resolver::iterator it = slv.resolve(qry);
ip::tcp::resolver::iterator end;
vector<string> ip;
for (; it != end; it++)
{
ip.push_back((*it).endpoint().address().to_string());
} for (int i = ; i < ip.size(); i++)
{
cout << ip[i] << endl;
}
getchar();
return ;
}