返回列表 發帖

字串的處理 - 英文大小寫轉換

本帖最後由 tonyh 於 2012-4-21 16:34 編輯

將英文字串轉換為大寫或小寫.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char string[50];               //宣告一字串陣列
  7.     cout<<"請輸入要轉換的英文字串(50字內): ";
  8.     cin.getline(string,50);        //抓取字串, 其長度為50字元
  9.     strlwr(string);                //strlwr 為 'string lower' 的縮寫
  10.     cout<<"轉換成小寫: "<<string<<endl;
  11.     strupr(string);                //strupr 為 'string upper' 的縮寫
  12.     cout<<"轉換成大寫: "<<string<<endl;
  13.     system("pause");
  14.     return 0;
  15. }
複製代碼

返回列表