0

When I try to use tolower on a string, rather than making the letters lowercase, the program converts them to random symbols. Here is my code:

#include <iostream>
#include <locale>
using namespace std;

int main()
{
    string hi= "thTSMSdjNnJlJjnJJKn";
    for (int i=0; i<hi.length(); i++)
    {
        hi[i]+=tolower(hi[i]);
        cout << hi[i];
    }
}

This is the output: Þð╚ã║ã╚È╝▄┤Ï┤È▄┤┤Â▄

What is wrong with it? This isn't the actual code that I want to use tolower on but I just put it in a separate example so it was more clear. I don't mind using to upper either but the main thing is that I get all the letters in the string to be the same case.

Jonas
  • 6,915
  • 8
  • 35
  • 53

1 Answers1

3

There's a typo in the for loop:

hi[i] += tolower(hi[i]);

should be

hi[i] = tolower(hi[i]);

Also, your code is missing #include <string>

roalz
  • 2,699
  • 3
  • 25
  • 42