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

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

 1 #include "stdafx.h"
 2 #include "boost/asio.hpp"
 3 #include <boost/lexical_cast.hpp>
 4 
 5 using namespace std;
 6 using namespace boost::asio;
 7 
 8 int _tmain(int argc, _TCHAR* argv[])
 9 {
10     boost::asio::io_service ios;
11     //创建resolver对象
12     ip::tcp::resolver slv(ios);
13     //创建query对象
14     ip::tcp::resolver::query qry("www.google.com", boost::lexical_cast<string>(0));
15     //使用resolve迭代端点
16     ip::tcp::resolver::iterator it = slv.resolve(qry);
17     ip::tcp::resolver::iterator end;
18     vector<string> ip;
19     for (; it != end; it++)
20     {
21         ip.push_back((*it).endpoint().address().to_string());
22     }
23     
24     for (int i = 0; i < ip.size(); i++)
25     {
26         cout << ip[i] << endl;
27     }
28     getchar();
29     return 0;
30 }
原文地址:https://www.cnblogs.com/tyche116/p/9360407.html