#include<iostream>#include<string>#include<cctype>using namespace std;int main(){string s1;cin>>s1;cout<<tolower(s1)<<endl;return 0;} [Error] error: no matching function for call to `tolower(std::string&)'[Warning] note: candidates are: int tolower(int)我就是想試試這個(gè)函數(shù)的功能,也包含了頭文件cctype,哪里出錯(cuò)了呢
2 回答

慕俠2389804
TA貢獻(xiàn)1719條經(jīng)驗(yàn) 獲得超6個(gè)贊
tolower函數(shù),就是把大寫字母轉(zhuǎn)成小寫字母。
為了使函數(shù)更健壯,可以在入口處添加對(duì)參數(shù)范圍的判斷,只對(duì)大寫字母操作。
由于函數(shù)功能簡(jiǎn)單,所以tolower最好設(shè)置為內(nèi)聯(lián)函數(shù)(inline)。
代碼如下:
123456 | inline char tolower ( char c) { if (c >= 'A' && c<= 'Z' ) //是大寫字母,執(zhí)行轉(zhuǎn)換。 c+= 'a' - 'A' ; //轉(zhuǎn)成大寫。 return c; } |
添加回答
舉報(bào)
0/150
提交
取消