Avoid atoi, use std::stoi(), etc.

This is closer to the C++ standard and also avoids some casts.