Google News
logo
C++ Program to Convert Lowercase to Uppercase
In the following example of C++ program that converts lowercase letters to uppercase using the standard library function toupper() :
Program :
#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;

int main()
{
    char str[100];
    cout << "Enter a string: ";
    cin.getline(str, 100);
    int len = strlen(str);

    for (int i = 0; i < len; i++) {
        if (islower(str[i])) {
            str[i] = toupper(str[i]);
        }
    }

    cout << "Uppercase string: " << str << endl;
    return 0;
}
Output :
Enter a string: freetimelearning.com
Uppercase string: FREETIMELEARNING.COM
In this program, we first read a string from the user using cin.getline(). We then use a loop to iterate over each character in the string. If the character is lowercase, we convert it to uppercase using the toupper() function. Finally, we print the uppercase string to the console using cout.