How to achive this task

So heres a string:- string x = "1hello"; And I want to convert the first char to a int:- //Using stoi() int y = stoi(x.at(0),nullptr); And the compiler summoned a pokemon (Error) So yeah , How to do that? How to basically convert the char to a int?

4/18/2019 3:14:14 AM


1 Answer

New Answer


Use static_cast<type>(value) i subtract '0' because casting it returns the character's hex value as int. https://code.sololearn.com/cjbc2TBXAAHO/?ref=app