Horje
How to Convert a C++ String to Uppercase?

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: horje

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 = "horje";
    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: horje
String after conversion to uppercase: GEEKSFORGEEKS



Reffered: https://www.geeksforgeeks.org


C++

Related
How to Read Input Until EOF in C++? How to Read Input Until EOF in C++?
What is an Undefined Reference Error in C++? What is an Undefined Reference Error in C++?
How to Fix Undefined Reference Error in C++? How to Fix Undefined Reference Error in C++?
How to Check if a Template Class has the Given Member Function in C++? How to Check if a Template Class has the Given Member Function in C++?
How to Ask User Input Until Correct Input is Received? How to Ask User Input Until Correct Input is Received?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13