C++轉換大小寫

函數 ------------------------說明

toupper(c) c是小寫就返回大寫;否則原樣返回
tolower(c) c是大寫就返回小寫;否則原樣返回

頭文件

#include <cctype> 

下面一個例題;

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
void g(char *p);
int main()
{ char s[100];
cin.getline(s,100);
g(s);
cout<<s<<endl;
return 0;
}
void g(char *p)
{int len=strlen(p);//測量長度
for(int i=0;i<len;i++)
p[i]=toupper(p[i]);
}

在這裏插入圖片描述
在這裏插入圖片描述

發佈了15 篇原創文章 · 獲贊 18 · 訪問量 8230
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章