How do I convert a string to an int in c++? The simplest way is to use the function int std::atoi(const char*) declared in cstdlib. For example, std::atoi(“42″) returns 42. Alternatively, you can use std::strtol() or std::strtoul(). These functions provide more functionality such as the ability to convert hexadecimal or octal number strings, and are [...]