0
Conversion of String Equation to Integer not working
I just started learning C++ and I had a problem with converting a string operations into an integer. Id like some tips on code as well. Thanks in advance! :) https://code.sololearn.com/cm0110Y9r091/?ref=app
2 Antworten
+ 2
atoi doesn't perform operation. It only converts the string to int. If you do atoi("9 - 7"); It returns 9 because the character after 9 is not a valid digit.
A side notes:
Don't use atoi. In C++ there is std::stoi which takes an std::string. You won't need to convert the string to char array with stoi. (stoi still doesn't perform operation though)
You either do using namespace std or write std:: manually. I don't see the purpose of 4 usings here.
Instead of changing "1 character", with replace, just use str[pos] = '+'.
0
CarrieForle Thanks for the input, im gonna try a different approach to this problem :)