Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Difficulty Level : Easy
  • Last Updated : 06 Jul, 2017

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

Examples:

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!