O
O
omerkhan2021-12-18 15:27:43
C++ / C#
omerkhan, 2021-12-18 15:27:43

How to convert char to int?

string s = to_string(n);
ll ans = 0;
for (int i = 0; i < s.size(); i++) {
  ans = stoi(s[i]);
}

Works for string, but how to do it for char?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-12-18
@omerkhan

If you need, for example, the symbol of the number 5 to be converted into the number 5, then like this:

char fiveDigit = '5';
int fiveNumber = fiveDigit - '0';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question