Search code examples
c++decimalstandardsradixstrtol

Does the Standard Define Common Bases?


strtol, for example, takes a base as its last argument

I find passing in the magic number 10 in all over my code to be unappealing. Is the decimal base already defined somewhere in the standard?


Solution

  • I don't think there's any standard base definition for use with strtol. However, there are alternative conversion functions, which have 10 as the default argument for base, such as std::stoi which works on std::strings, and the new std::from_chars which works on const char*s.