I am determining the length of certain strings of characters in C++ with the function length()
, but noticed something strange: say I define in the main
function
string str;
str = "canción";
Then, when I calculate the length of str
by str.length()
I get as output 8
. If instead I define str = "cancion"
and calculate str
's length again, the output is 7
. In other words, the accent on the letter 'o' is altering the real length of the string. The same thing happens with other accents. For example, if str = "für"
it will tell me its length is 4
instead of 3
.
I would like to know how to ignore these accented characters when determinig the lenght of a string; however, I wouldn't want to ignore isolated characters like '
. For example, if str = livin'
, the lenght of str
must be 6
.