C++ function to convert string to int