#include#include int main() { const char str[] = "123"; int i = std::atoi(str); std::cout << i << std::endl; // Output: 123 return 0; }
#includeIn this example, we declare a C-style string "str" that contains non-numeric characters at the beginning. When we apply the atoi function to this string, it does not convert any characters and returns 0. The std atoi function is part of the standard C library (stdlib.h/cstdlib). It is used in the C++ standard library as well.#include int main() { const char str[] = "abc123"; int i = std::atoi(str); std::cout << i << std::endl; // Output: 0 return 0; }