#include <cstdlib>
#include <iostream>
int main()
{
const auto strings_with_numbers = {
"89",
"0x3A", // "0" and string - not hexadecimal
"3.14159",
"84933 c++ programmming",
"c/c++ 20",
"-0409",
"900000000000" // out of int32 range
};
for (const char* str : strings_with_numbers) {
const int i{std::atoi(str)};
std::cout << "std::atoi('" << str << "') = " << i << '\n';
if (const long long ll{std::atoll(str)}; i != ll) {
std::cout << "std::atoll('" << str << "') = " << ll << " string to long long\n";
}
}
}
/*
run:
std::atoi('89') = 89
std::atoi('0x3A') = 0
std::atoi('3.14159') = 3
std::atoi('84933 c++ programmming') = 84933
std::atoi('c/c++ 20') = 0
std::atoi('-0409') = -409
std::atoi('900000000000') = -1943132160
std::atoll('900000000000') = 900000000000 string to long long
*/