How would I convert an ip address into bytes in C++? Basically how do I parse the IP address? For example, if I have a string equal to 121.122.123.124
.
I need
If the pattern is constant, number dot number dot etc, then use istringstream:
#include
using namespace std;
int byte1, byte2, byte3, byte4;
char dot;
char *ipaddress = "121.122.123.124";
istringstream s(ipaddress); // input stream that now contains the ip address string
s >> byte1 >> dot >> byte2 >> dot >> byte3 >> dot >> byte4 >> dot;