Skip to content
Related Articles

Related Articles

Conversion of whole String to uppercase or lowercase using STL in C++

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 18 May, 2022

Given a string, convert the whole string to uppercase or lowercase using STL in C++.

CPP-STL-Self-Paced-Course

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 write.geeksforgeeks.org or mail your article to review-team@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.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!