cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Convert string IP to unsigned int
Convert string IP to unsigned int
Nov 10, 2014 at 10:03pm UTC
cybermonkeyso
(20)
I need to convert a string IP to an unsigned int (uint32), but however solutions I've found elsewhere have not worked (such as `atoi`).
When using `(uint32)"54.171.82.217\0 ";` :
http://puu.sh/cLw2j/d590a8ac1b.png
When using `atoi("54.171.82.217");`:
http://puu.sh/cLwm7/07cdb8e46e.png
How can I correctly convert the string version of the IP to the uint32 type?
Nov 11, 2014 at 11:37am UTC
cybermonkeyso
(20)
I ended up using `inet_addr("54.171.82.217")` instead.
Bear in mind that it needs `WinSock2.h` and the `Ws2_32.lib` library (can be simply `#pragma comment(lib, "Ws2_32.lib"`).
Topic archived. No new replies allowed.