logo

tolower() Funció en C++

El C++ abaixar() La funció converteix un alfabet en majúscules en un alfabet en minúscules. És una funció predefinida de ctype.h fitxer de capçalera. Si el caràcter passat és un alfabet en majúscules, la funció tolower() converteix un alfabet en majúscules en un alfabet en minúscules. Aquesta funció no afecta cap altre caràcter en minúscula, símbol especial o dígit.

int tolower(int ch);>

Paràmetre:



    ch: És el caràcter que s'ha de convertir a minúscules.

Valor de retorn: Aquesta funció retorna el valor ASCII del caràcter en minúscula corresponent a la cap.

En C++, la conversió d'int a char es fa de la següent manera:

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

Els programes següents il·lustren la funció 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);> }>

>

>

Sortida

G in lowercase is represented as = g>

Exemple 2:

canyella vs mate

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;> }>

>

>

Sortida

geeksforgeeks>

Nota: Si el caràcter passat a la part inferior () és qualsevol d'aquests tres

  1. caràcter en minúscula
  2. símbol especial
  3. dígit

tolower() retornarà el caràcter tal com és.

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;> }>

>

>

Sortida

geeks@123>