+ 2
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?
1 ответ
+ 1
In this snippet, I subtracting the ASCII value of '0' from the first character of the string, which effectively converts it to its integer value.
See this code⤵️
https://sololearn.com/compiler-playground/cYGdjvnDLcQw/?ref=app