-1

I have a string of characters and one of those possible characters is the letter "ñ". My problem is, my string seems to behave in a weird way when I try to modify it or iterate through the string. For example if I have the code:

std::ifstream infile (argv[1]);
std::string texto_crudo((std::istreambuf_iterator<char>(infile)), std::istreambuf_iterator<char>());
for (int i = 0; i<texto_crudo.length(); i++){
    if(es_enie(texto_crudo[i])) {
        texto_crudo[i] = '$';
    }
}

Where es_enie returns true if texto_crudo[i] = ñ. It seems like in the cell where ñ is located it behaves as if it has two values instead of one.

darclander
  • 1,526
  • 1
  • 13
  • 35
Gessio26
  • 17
  • 4

1 Answers1

-1

I managed to find a solution to my exact problem. As Some programmer dude commented, it was because my text was in UTF-8 and I needed to convert it to iso-8859-1 in order to be able to use "ñ" correctly. Convert string from UTF-8 to ISO-8859-1

Gessio26
  • 17
  • 4
  • Alternatively, you can fix `es_enie` so that it takes utf8 input. Characters are not necessarily 1 `char` long – Caleth May 13 '20 at 11:57