mercredi 4 septembre 2019

the base argument of std::stoi

The stoi function of c++ is defined as:

int stoi(const std::string& str, std::size_t* pos = 0, int base = 10);

as you can see, the base argument is defaulted as 10, so by default it could only handle decimal numbers. By setting base to 0, it could handle numbers by their prefixes. This is same behavior as strtol, so why is the default value being set to 10, rather than 0?

Aucun commentaire:

Enregistrer un commentaire