Discussion:
[asio-users] ip::address::from_string() not working
Darren Cook
2012-02-10 09:47:16 UTC
Permalink
ip::address's from_string() function does not seem to be working; it
gives me 0.0.0.0 whatever string I pass.

A very minimal reproducible example below, it outputs:
Set host to 0.0.0.0

I'm using boost 1.40 (ubuntu 10.04). Google is strangely quiet; so I
guess I'm doing something wrong??

Darren


//Compile and run with "g++ test.cpp -lboost_system;./a.out"

#include <iostream>
#include <boost/asio.hpp>

int main(int argc, char* argv[])
{
boost::asio::ip::address host;
host.from_string("127.0.0.1");
std::cout<<"Set host to "<<host<<"\n";
return 0;
}
--
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
niXman
2012-02-10 10:22:28 UTC
Permalink
'boost::asio::ip::address::from_string()' is a static member function:
http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/reference/ip__address/from_string.html

usage:
#include <iostream>
#include <boost/asio.hpp>

int main(int argc, char* argv[])
{
boost::asio::ip::address host =
boost::asio::ip::address::from_string("127.0.0.1");
std::cout<<"Set host to "<<host<<"\n";
return 0;
}

http://liveworkspace.org/code/eda650ea2820edf01b09cb2594856ef5

Regards.
niXman.
Post by Darren Cook
ip::address's from_string() function does not seem to be working; it
gives me 0.0.0.0 whatever string I pass.
 Set host to 0.0.0.0
I'm using boost 1.40 (ubuntu 10.04). Google is strangely quiet; so I
guess I'm doing something wrong??
Darren
//Compile and run with "g++ test.cpp -lboost_system;./a.out"
#include <iostream>
#include <boost/asio.hpp>
int main(int argc, char* argv[])
{
   boost::asio::ip::address host;
   host.from_string("127.0.0.1");
   std::cout<<"Set host to "<<host<<"\n";
   return 0;
}
--
Darren Cook, Software Researcher/Developer
http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Darren Cook
2012-02-13 05:17:01 UTC
Permalink
Post by niXman
...
boost::asio::ip::address host =
boost::asio::ip::address::from_string("127.0.0.1");
Thanks niXman, that worked! (I had tried using it statically, after
finding an example on the web somewhere, but I got a segmentation error;
it must have been an unlucky coincidence.)

Darren
--
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
Loading...