convert a string xxx.xxx.xxx.xxx in a number (CIDR format)

Franco Amato eurofrank at gmail.com
Fri May 4 18:04:24 PDT 2007


Thank to all.
To extract every field from the full entiere strind (xxx.xxx.xxx.xxx - every
fiels is a single xxx)
I used the strtok()...is there an analogue function in c++?
Regards
Frank


2007/5/4, Carsten A. Arnholm <arnholm at offline.no>:
>
>
> Friday, May 4, 2007, 2:07:18 PM, you wrote:
> > Hi people, sorry in advance for the off-topic question.
> > I have to convert a string in the format 255.255.255.0 in a number
> > (in this example 30).
> > code in C standard....
> > to convert a single octet (255 =3D 7, int to int) is not a problem, the
> > problem is convert a string.
> > For example if I have char vett[3] where vett[0]=3D2 vett[1]=3D5 and
> > vett[2]=3D5, how can I convert it in a int with the value 255???
> > Thank you
> > Franco
>
> Hi Franco,
>
> In C++ I would maybe do
>
> #include <sstream>
> #include <iostream>
> using namespace std;
> int main()
> {
>    char vett[] =3D "255";
>    int ivalue =3D 0;
>    istringstream in(vett);
>    in >> ivalue;
>    cout << ivalue << endl;
>    return 0;
> }
>
> In plain C you could possibly use the atoi function
>
> int i;
> i =3D atoi(vett );
>
> --
> Carsten A. Arnholm
> http://arnholm.org/
> N59.776 E10.457
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20070504/482=
82240/attachment.htm


More information about the wx-users mailing list