V
V
Victor Marquardt2016-11-17 22:07:21
JavaScript
Victor Marquardt, 2016-11-17 22:07:21

Is there an analogue of str.charCodeAt(index) for C++?

Need an analogue of charCodeAt from js for C++. If not, please tell me how to do the same in C++. Give an example if possible.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitaly, 2016-11-17
@Cempl

For a regular string:

std::string s("foo");
int code = s[0]; // 102

A
Adamos, 2016-11-17
@Adamos

"For C++" is too vague.
If we are talking about single-byte strings (char[], char* or std::string), then str[idx] will be the value you need.
But only if the content is in the same single-byte encoding.
And if there, say, utf-8, then here you are unlikely to do without the appropriate library.

V
Veliant, 2016-11-17
@Veliant

ord(str[idx]) not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question