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

【boost.asio学习-----reslover|boost.asio学习-----reslover 域名解析】将域名解析为ip地址并输出:

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


转载于:https://www.cnblogs.com/tyche116/p/9360407.html

    推荐阅读