How to convert string to lower case or UPPER case in C++ ? Sep 8, 2024 • Written by Nadir SOUALEM How to convert string to lower case or UPPER case in C++ ? The fast way to convert is to use transform algorithm associated to lower and upper function. #include <algorithm> #include <string> #include <iostream> using namespace std; int main(){ string data = "ABc1#@23yMz"; transform(data.begin(), data.end(), data.begin(),(int (*)(int))toupper); cout << data << endl; transform(data.begin(), data.end(), data.begin(),(int (*)(int))tolower); cout << data << endl; } Result: ABC1#@23YMZ abc1#@23ymz To avoid pointers to function, use operator :: #include <algorithm> #include <string> #include <iostream> using namespace std; int main(){ string data = "ABc1#@23yMz"; transform(data.begin(), data.end(), data.begin(),::toupper); cout << data << endl; transform(data.begin(), data.end(), data.begin(),::tolower); cout << data << endl; } If you found this post or this website helpful and would like to support our work, please consider making a donation. Thank you! Help Us Articles in the same category How to sum elements of a C++ std::vector ? How to split a string in C++ using STL ? How to print the elements of a C++ std::vector with GNU Debugger GDB ? How to get command-line parameters in a C++ vector ? How to convert string to lower case or UPPER case in C++ ? C++ - Faq C++ STL