Convert string to lowercase or uppercase in C++

 In this example, You learn about C++ program for convert string to lower case and upper case. 

Here you learn convert string to lower case and upper case in C++, You are given a string and the task of the program to find convert string to lower case and upper case.

C++ Program for Convert String to Lower Case and Upper Case

#include <iostream>
using namespace std;

void lowerString(string str)
	for(int i=0;str[i]!='\0';i++)
		if (str[i] >= 'A' && str[i] <= 'Z') //checking for uppercase characters
			str[i] = str[i] + 32;           //converting uppercase to lowercase
	cout<<"\n The String in Lower Case: "<< str;

void upperString(string str)
	for(int i=0;str[i]!='\0';i++)
		if (str[i] >= 'a' && str[i] <= 'z') //checking for lowercase characters
			str[i] = str[i] - 32;           //converting lowercase to uppercase
	cout<<"\n The String in Upper Case: "<< str;

int main()
	string str;
    cout<<"Enter the String: ";
    lowerString(str);   //function call for convert string to lowercase
	upperString(str);   //function call for convert string to uppercase
	return 0;

Enter the String: CoDEamY
 The String in Lower Case: codeamy
 The String in Upper Case: CODEAMY

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form