Open In App

How to Convert a C++ String to Uppercase?

Last Updated : 01 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In C++, converting a string to uppercase means we have to convert each character of the string that is in lowercase to an uppercase character. In the article, we will discuss how we can convert a string to uppercase in C++.

Example

Input: geeksforgeeks

Output: GEEKSFORGEEKS

Converting String to Uppercase in C++

In C++, we can convert a string to uppercase using the toupper() function that converts a character to uppercase. We will apply this function to each character in the string using std::transform() function.

C++ Program to Convert a String to Uppercase

C++




// C++ program to convert a string to uppercase
#include <algorithm> // for using transform
#include <cctype> // for using toupper
#include <iostream>
#include <string>
using namespace std;
  
int main()
{
  
    string myStr = "geeksforgeeks";
    cout << "Input String is: " << myStr << endl;
  
    // using transform with toupper to convert mystr to
    // uppercase
    transform(myStr.begin(), myStr.end(), myStr.begin(),
              ::toupper);
  
    // printing string after conversion
    cout << "String after conversion to uppercase: "
         << myStr << endl;
  
    return 0;
}


Output

Input String is: geeksforgeeks
String after conversion to uppercase: GEEKSFORGEEKS

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads