converting from IPADDRESS string to unsigned char array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sam.barker0@gmail.com

    converting from IPADDRESS string to unsigned char array

    Hi ,
    I am trying to convert from an IPADDRESS string [say "12.12.1.2"]to a
    unsigned char array[containing the octets witout the dots]

    I tried to use c_str().Its was stupid because I tried to cast it with
    <unsigned int.
    Is there a way easily do this.

    Cheers,
    Sam
  • Obnoxious User

    #2
    Re: converting from IPADDRESS string to unsigned char array

    On Sun, 30 Mar 2008 05:32:28 -0700, sam.barker0 wrote:
    Hi ,
    I am trying to convert from an IPADDRESS string [say "12.12.1.2"]to a
    unsigned char array[containing the octets witout the dots]
    >
    I tried to use c_str().Its was stupid because I tried to cast it with
    <unsigned int.
    Is there a way easily do this.
    >
    #include <sstream>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <iterator>

    std::istream & operator>>(std: :stringstream & strm, std::vector<int & v) {
    if(strm.good()) {
    int temp = ~0;
    strm >temp;
    v.push_back(tem p);
    }
    return strm;
    }

    int main() {
    std::stringstre am stream("12.12.1 .12");
    std::vector<int v;
    while(stream.go od()) {
    stream >v;
    stream.ignore() ;
    }
    std::copy(v.beg in(),v.end(),st d::ostream_iter ator<int>(std:: cout,"\n"));
    return 0;
    }

    --
    OU

    Comment

    • sam.barker0@gmail.com

      #3
      Re: converting from IPADDRESS string to unsigned char array

      Hi,
      Thanks for the reply.But
      I need the result in an unsigned char array.

      Comment

      Working...