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
121.122.123.124
Use inet_aton.
#include #include #include int main(int argc, char *argv[]) { std::string s; in_addr addr; while(std::cin >> s && inet_aton(s.c_str(), &addr)) { std::cout << inet_ntoa(addr) << "\n"; } }