Given a string, convert the whole string to uppercase or lowercase using STL in C++.
Examples:
For uppercase conversion Input : s = "String" Output : s = "STRING" For lowercase conversion Input : s = "String" Output : s = "string"
Functions used :
transform : Performs a transformation on given array/string.
toupper(int c) : Returns upper case version of character c. If c is already in uppercase, return c itself.
tolower(int c) : Returns lower case version of character c. If c is already in lowercase, return c itself.
// C++ program to convert whole string to // uppercase or lowercase using STL. #include<bits/stdc++.h> using namespace std; int main() { // su is the string which is converted to uppercase string su = "Jatin Goyal" ; // using transform() function and ::toupper in STL transform(su.begin(), su.end(), su.begin(), :: toupper ); cout << su << endl; // sl is the string which is converted to lowercase string sl = "Jatin Goyal" ; // using transform() function and ::tolower in STL transform(sl.begin(), sl.end(), sl.begin(), :: tolower ); cout << sl << endl; return 0; } |
Output:
JATIN GOYAL jatin goyal
This article is contributed by Jatin Goyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.