+ 4

Conversion->lower ad uppercase

How to convert a string to lower and uppercase string

25th Nov 2017, 1:08 PM
I'm_Groot
I'm_Groot - avatar
2 ответов
+ 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]
25th Nov 2017, 1:33 PM
Babak
Babak - avatar
+ 1
there are fixed functions in all programming languages that do the job for you
25th Nov 2017, 1:37 PM
Dmitrii
Dmitrii - avatar