C++ の tower() 関数
C++ より低い() 関数は、大文字のアルファベットを小文字のアルファベットに変換します。あらかじめ定義されている関数です ctype.h ヘッダファイル。渡された文字が大文字のアルファベットの場合、to lower() 関数は大文字のアルファベットを小文字のアルファベットに変換します。この関数は、別の小文字、特殊記号、数字には影響しません。
int tolower(int ch);
パラメータ:
- ch: 小文字に変換する文字です。
戻り値: この関数は、 小文字 に対応する ch.
C++ では、int から char への型キャストは次のように行われます。
char c = (char) tolower('A'); 以下のプログラムは、C++ の to lower() 関数を示しています。
例 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);> }> |
出力
G in lowercase is represented as = g
例 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;> }> |
出力
geeksforgeeks
注記: to lower() で渡された文字がこれら 3 つのいずれかである場合
- 小文字
- 特殊な記号
- 桁
to lower() は文字をそのまま返します。
例 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;> }> |
出力
geeks@123