reading an IP address from argv forces me to convert it to uint32_t
this function will do so:
uint32_t convert_string_ip_to_uint32_t (const string & string_ip) { stringstream s(string_ip) ; uint16_t a,b,c,d; //to store the 4 ints char ch; //to temporarily store the '.' s >> a >> ch >> b >> ch >> c >> ch >> d ; std::cout << a << " " << b << " " << c << " "<< d << std::flush;; return ((uint32_t) a << 24 | b << 16 | c << 8 | d); }
But when I change the data type of a,b,c and d to uint8_t, the result will be rubish. Why? e.g. string_ip = '192.168.1.10'
Aucun commentaire:
Enregistrer un commentaire