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

25th Mar 2021, 9:28 AM
Marc Stephen Gabres
Marc Stephen Gabres - avatar
2 RĂ©ponses
+ 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] = '+'.
25th Mar 2021, 10:54 AM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
0
CarrieForle Thanks for the input, im gonna try a different approach to this problem :)
26th Mar 2021, 2:00 AM
Marc Stephen Gabres
Marc Stephen Gabres - avatar