将字符串传换成小写字符串tolower函数

tolower是一种函数,功能是把字母字符转换成小写。

功 能: 把字符转换成小写字母,非字母字符不做出处理
头文件:在VC6.0可以是ctype.h或者stdlib.h,常用ctype.h
目前在头文件iostream中也可以使用,C++ 5.11已证明。
用 法: int tolower(int c);
说明:和函数int _tolower( int c );功能一样,但是_tolower在VC6.0中头文件要用ctype.h
注:函数详细的解释可以看百度百科。
 1 int main()
 2 {
 3         //tolower函数
 4     string str= "THIS is A STRING";
 5         //或者是string str= "THIS IS A STRING";
 6     for (int i=0; i <str.size(); i++)
 7     {
 8         str[i] = tolower(str[i]);
 9     }
10 
11     cout<<str<<endl;
12       
13         return 0;
14 }

函数的运行结果如下:

(代码中注释部分的运行结果也是下面这个结果)

原文地址:https://www.cnblogs.com/LYF-LIUDAO/p/7017746.html