How to achive this task | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Resposta
+ 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