You can simply input four integers along with three dot characters. (Hints : 7 cin statements in total)
Last edited on
I couldn't do that. part of the program, afterward is having to convert said IP address into 32 bit integer, so it would have to be altogether.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
std::string str_ip = "Please enter a correct IP address : ";
cout << str_ip; cin >> str_ip;
std::stringstream ss(str_ip);
int v = 0, n = 3; uint32_t real_ip;
while(true)
{
if(ss >> v && n >= 0)
{
char c;
((uint8_t*)&real_ip)[n] = v;
ss >> c;
} else break;
n--;
}
cout << "The IP address entered : " << real_ip << endl;
|
Please enter a correct IP address : 124.186.205.63
The IP address entered : 2092617023 |
Last edited on