Answer the question
In order to leave comments, you need to log in
C++ how to count characters in a string?
C++ There is a variable of type String, it contains Russian and English letters, spaces and punctuation marks.
You need to count the number of characters in this string, including spaces and signs.
The problem is that when using length() or size() , the result is not accurate for some reason. Shows the correct number of characters for English letters and multiplied by 2 for Cyrillic.
How can this problem be solved?
Thank you!
Answer the question
In order to leave comments, you need to log in
wstring_convert< codecvt_utf8<char32_t>, char32_t >().from_bytes(the_std_string).size()
well, probably the string uses some kind of utf-x, look at what you have, after that it's quite easy to count the characters.
UPDATE: if utf, then not some kind of course, but utf-8.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question