How to achive this task | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answer
0
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
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar