複製鏈接
請複製以下鏈接發送給好友

tolower

鎖定
tolower是一種函數,功能是把字母字符轉換成小寫,非字母字符不做出處理。和函數int _tolower( int c )功能一樣,但是_tolower在VC6.0中頭文件要用ctype.h
外文名
tolower
功 能
把字母字符轉換成小寫
頭文件
在VC6.0可以是ctype.h
用 法
int tolower(int c);

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

tolowerC程序例

#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
    int i;
    char string[] = "THIS IS A STRING";
    printf("%s\n", string);
    for (i = 0; i < strlen(string); i++)
    {
        putchar(tolower(string[i]));
    }
    printf("\n");
    system("pause");//系統暫停,有助於查看結果
}

tolowerC++程序例

#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
    string str= "THIS IS A STRING";
    for (int i=0; i <str.size(); i++)
       str[i] = tolower(str[i]);
    cout<<str<<endl;
    return 0;
}

tolowerC源碼示例

//Converts c to its lowercase equivalent if c is an uppercase letter and has a lowercase equivalent.
//If no such conversion is possible, the value returned is c unchanged.
int tolower (int c)
{
  return (c >= 'A' && c <= 'Z')?(c - 'A' + 'a'):c;
}