I'm trying to convert the string variable passed by reference to a decimal. When I put in a string in quotes using atoi it works, but not with a string variable. What should I do instead?
void stringDecision(string& assembledString) {
double convertedString; // conversion to double
// remove unary + operator because it's unnecessary
if (assembledString[0] == '+' && assembledString.length() > 1)
{
assembledString.erase(0, 1);
cout << assembledString;
convertedString = atoi(assembledString);
}
else
{
cout << "I'm an operator " << assembledString;
}
}