rectangletangle rectangletangle - 8 months ago 55
C++ Question

How do I change the case of a string in C++?

I have a string that may contain numbers as well as upper and lower case letters. I need to convert all the uppercase letters to lowercase and vice versa. How would one go about this?

Answer Source

Iterate the string and use isupper() to determine if each character is uppercase or not. If it's uppercase, convert it to lowercase using tolower(). If it's not uppercase, convert it to uppercase using toupper().