Using the islower(), isupper(), tolower() and toupper() functions C++ code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Testing the characters using islower(), isupper(), tolower() and toupper() functions in C++ programming

To show: How to use the islower(), isupper(), tolower() and toupper() functions in C++ programming

 

// using functions islower(), isupper(), tolower() and toupper() function example.

// for C++ string character & string manipulation it is better to use the Standard Template Library, STL

#include <iostream>

using namespace std;

 

int main(void)

{

cout<<"Using functions islower(), isupper(),"<<endl;

cout<<"tolower(), toupper()"<<endl;

cout<<"-------------------------------------"<<endl;

cout<<"\nAccording to islower():"<<endl;

islower('p') ? cout<<"p is a lowercase letter"<<endl : cout<<"p is not a lowercase letter"<<endl;

islower('P') ? cout<<"P is a lowercase letter"<<endl : cout<<"P is not a lowercase letter"<<endl;

islower('5') ? cout<<"5 is a lowercase letter"<<endl : cout<<"5 is not a lowercase letter"<<endl;

islower('!') ? cout<<"! is a lowercase letter"<<endl : cout<<"! is not a lowercase letter"<<endl;

 

cout<<"\nAccording to isupper():"<<endl;

isupper('D') ? cout<<"D is a uppercase letter"<<endl : cout<<"D is not a uppercase letter"<<endl;

isupper('d') ? cout<<"d is a uppercase letter"<<endl : cout<<"d is not a uppercase letter"<<endl;

isupper('8') ? cout<<"8 is a uppercase letter"<<endl : cout<<"8 is not a uppercase letter"<<endl;

isupper('$') ? cout<<"$ is a uppercase letter"<<endl : cout<<"$ is not a uppercase letter"<<endl;

 

cout<<"\nConversion...."<<endl;

cout<<"u converted to uppercase is "<<(char)toupper('u')<<endl;

cout<<"7 converted to uppercase is "<<(char)toupper('7')<<endl;

cout<<"$ converted to uppercase is "<<(char)toupper('$')<<endl;

cout<<"L converted to lowercase is "<<(char)tolower('L')<<endl;

 

return 0;

}

 

Output example:

 

Using functions islower(), isupper(),

tolower(), toupper()

-------------------------------------

According to islower():

p is a lowercase letter

P is not a lowercase letter

5 is not a lowercase letter

! is not a lowercase letter

 

According to isupper():

D is a uppercase letter

d is not a uppercase letter

8 is not a uppercase letter

$ is not a uppercase letter

 

Conversion....

u converted to uppercase is U

7 converted to uppercase is 7

$ converted to uppercase is $

L converted to lowercase is l

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index