O
Obnoxious User
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(temp);
}
return strm;
}
int main() {
std::stringstream stream("12.12.1.12");
std::vector<int> v;
while(stream.good()) {
stream >> v;
stream.ignore();
}
std::copy(v.begin(),v.end(),std:stream_iterator<int>(std::cout,"\n"));
return 0;
}