Fonction tolower() en C++

Le C++ baisser() La fonction convertit un alphabet majuscule en alphabet minuscule. C'est une fonction prédéfinie de ctype.h En tête de fichier. Si le caractère transmis est un alphabet majuscule, alors la fonction tolower() convertit un alphabet majuscule en alphabet minuscule. Cette fonction n'affecte pas les autres caractères minuscules, symboles spéciaux ou chiffres.

int tolower(int ch); 

Paramètre:

    ch : C'est le caractère à convertir en minuscule.

Valeur de retour : Cette fonction renvoie la valeur ASCII du caractère minuscule correspondant à la ch.

En C++, le transtypage de int en char se fait comme suit :

char c = (char) tolower('A'); 

Les programmes ci-dessous illustrent la fonction tolower() en C++ :

Exemple 1:

C++




// C++ program to demonstrate> // example of tolower() function.> > #include> using> namespace> std;> > int> main()> {> > > char> c => 'G'> ;> > > cout < < c < <> ' in lowercase is represented as = '> ;> > > // tolower() returns an int value there for typecasting> > // with char is required> > cout < < (> char> )> tolower> (c);> }>

Sortir

G in lowercase is represented as = g 

Exemple 2 :

C++




// C++ program to convert a string to lowercase> // using tolower> #include> using> namespace> std;> > int> main()> {> > > // string to be converted to lowercase> > string s => 'GEEKSFORGEEKS'> ;> > > for> (> auto> & x : s) {> > x => tolower> (x);> > }> > > cout < < s;> > return> 0;> }>

Sortir

geeksforgeeks 

Note: Si le caractère passé dans tolower() est l'un de ces trois

  1. caractère minuscule
  2. symbole spécial
  3. chiffre

tolower() renverra le caractère tel quel.

Exemple 3 :

C++




// C++ program to demonstrate> // example of tolower() function.> #include> using> namespace> std;> > int> main() {> > > string s=> 'Geeks@123'> ;> > > for> (> auto> x:s){> > > cout < < (> char> )> tolower> (x);> > }> > > return> 0;> }>

Sortir

geeks@123