How to Convert std::string to Lower Case? Last Updated : 04 Nov, 2024 Comments Improve Suggest changes Like Article Like Report Converting string to lower case means all the alphabets present in the string should be in lower case. In this article, we will learn how to convert the std::string to lowercase in C++.Examples Input: s = "GEEKS for GEEKS"Output: geeks for geeksExplanation: All characters of s are converted to lowercase.Input: s = "HelLO WoRld"Output: hello worldExplanation: All characters of s are converted to lowercase.Following are the 3 different methods to convert the std::string (C++ Style Strings) to lower case in C++:Table of ContentUsing std::transform()Using std::for_each()Manually Using ASCII ValuesUsing std::transform()We can convert the given std::string to lower case using std::transform() with std::tolower() method. This method applies the given tolower() function to each of the character converting it to lowercase if its not.Syntaxstd::transform(s.begin(), s.end(), s.begin(), ::tolower);where, s is the string to be converted.Example C++ // C++ Program to convert the std::string to // lower case using std::transform() #include <bits/stdc++.h> using namespace std; int main() { string s = "GEEKS for GEEKS"; // Converting the std::string to lower case // using std::transform() transform(s.begin(), s.end(), s.begin(), ::tolower); cout << s; return 0; } Outputgeeks for geeksTime Complexity: O(n), where n is the length of string.Auxiliary Space: O(1)Using std::for_each()We can also convert the given std::string to lower case using std::for_each loop with lambda function that convert the given character to its lower case using tolower() function.Example C++ // C++ Program to convert the std::string to // lower case using std::for_each loop with // lambda expression #include <bits/stdc++.h> using namespace std; int main() { string s = "GEEKS for GEEKS"; // Converting the std::string to lower case for_each(s.begin(), s.end(), [](char& c) { c = tolower(c); }); cout << s; return 0; } Outputgeeks for geeksTime Complexity: O(n), where n is the length of string.Auxiliary Space: O(1)Manually Using ASCII ValuesC++ uses ASCII charset in which characters are represented by 7-bit numbers called ASCII numbers. Also, lowercase alphabet for corresponding uppercase alphabet always differs by 32. So, we can use this property to convert each character of std::string to lowercase one by one by adding 32 to the uppercase character.Example C++ // C++ program to convert std::string to lowercase // manually using ASCII values #include <bits/stdc++.h> using namespace std; void toLowerCase(string& s) { // Manual converting each character to lowercase // using ASCII values for (char &c : s) { if (c >= 'A' && c <= 'Z') { // Convert uppercase to lowercase // by adding 32 c += 32; } } } int main() { string s = "GEEKS for GEEKS"; // Converting s to lowercase toLowerCase(s); cout << s; return 0; } Outputgeeks for geeksTime Complexity: O(n), where n is the length of string.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Convert std::string to Lower Case? B bhushanc2003 Follow Improve Article Tags : C++ Programs C++ STL cpp-string CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Convert a std::string to char* in C++? In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "Geeksfor 1 min read Convert char* to std::string in C++ Strings are generally represented as an instance of std::string class in C++. But the language also supports the older C-Style representation where they are represented as array of characters (char* or char[]) terminated by null character '\0'. In this article, we will learn how to convert the char* 3 min read How to Convert a Single Character to String in C++? A string is a generally made up of a sequence of multiple characters. In this article, we will learn how to convert a single character to a string in C++.Example:Input: c = 'A'Output: s = "a"Explanation: Character c is converted to a string.Input: c = '#'Output: s = "#"Explanation: Character c is co 4 min read How to Convert a C++ String to Uppercase? Converting a string to uppercase means changing each character of the string that is in lowercase to an uppercase character. In the article, we will discuss how to convert a string to uppercase in C++.ExamplesInput: str = "Geeksforgeeks"Output: GEEKSFORGEEKSExplanation: Every character of string con 3 min read How to Reverse a String in C++? Reversing a string means replacing the first character with the last character, second character with the second last character and so on. In this article, we will learn how to reverse a string in C++.ExamplesInput: str = "Hello World"Output: dlroW olleHExplanation: The last character is replaced by 2 min read Convert Camel Case String to Snake Case in C++ Programming can be complicated, and it's essential to ensure that our code is readable and well-structured. One way to improve code clarity is by using meaningful and descriptive variable and function names. To make every element name unique and more meaningful we use camel case and snake case are t 3 min read Convert String to Char Array in C++ In C++, we usually represent text data using the std::string object. But in some cases, we may need to convert a std::string to a character array, the traditional C-style strings. In this article, we will learn how to convert the string to char array in C++.ExamplesInput: str = "geeksforgeeks"Output 4 min read Convert character array to string in C++ This article shows how to convert a character array to a string in C++. The std::string in c++ has a lot of inbuilt functions which makes implementation much easier than handling a character array. Hence, it would often be easier to work if we convert a character array to string. Examples: Input: ch 4 min read How Do I Iterate Over the Words of a String? In C++, strings are character sequences stored in a char array. It may contain text in the form of multiple words representing a sentence. In this article, we will learn how we can iterate over the words of a string in C++. Example: Input: myString ="Geek for Geeks" Output: Geek for GeeksIterate Ove 2 min read Case-Insensitive String Comparison in C++ In C++, strings are sequences of characters that are used to store text data which can be in both uppercase and lowercase format. In this article, we will learn how we can compare two case-insensitive strings in C++. Example: Input: string1 = "WELCOME TO GEEKS FOR GEEKS"string2 = "welcome to geeks f 2 min read Like