+ 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?

18th Apr 2019, 3:14 AM
Shahil Ahmed
Shahil Ahmed - avatar
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
12th Apr 2024, 1:26 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar