+ 4
Conversion->lower ad uppercase
How to convert a string to lower and uppercase string
2 Answers
+ 19
A handy way, IMO, is using Xor operator.
#include <iostream>
#include <string>
int main() {
std::string str = "";
std::cout << "Enter your string : ";
getline(std::cin, str);
for (auto &i : str) {
if ((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z'))
i ^= 32;
}
std::cout << "Converted string is : " << str;
}
Possible output:
Enter your string : Hello, my FRIEND!
Converted string is : hELLO, MY friend!
[http://cpp.sh/2e7ee]
+ 1
there are fixed functions in all programming languages that do the job for you