返回列表 發帖

字串處理 (五) - 英文大小寫轉換

運用 strupr() 函式 與 strlwr() 函式進行英文大小寫轉換.
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     char str[50];
  8.     cout<<"輸入一字串: ";
  9.     cin.getline(str,50);
  10.     cout<<"你剛輸入的字串是: "<<str<<endl;
  11.     strupr(str);    //string upper
  12.     cout<<"轉換為大寫: "<<str<<endl;
  13.     strlwr(str);    //string lower
  14.     cout<<"轉換為小寫: "<<str<<endl;
  15.     system("pause");     
  16.     return 0;   
  17. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     int s;
  8.     char x[11];
  9.     cout<<"請輸入一段英文字:";
  10.     cin.getline(x,11);
  11.     cout<<endl<<endl;
  12.     cout<<"大寫:"<<strupr(x)<<endl;
  13.     cout<<endl<<endl;
  14.     cout<<"小寫:"<<strlwr(x)<<endl;
  15.     cout<<"字串的第"<<s<<"個字母為:"<<x[s-1]<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     char str[50];
  8.     cout<<"輸入一字串";
  9.     cin.getline(str,50);
  10.     cout<<"你剛剛輸入的字串是:"<<str<<endl;
  11.     strupr(str);
  12.     cout<<"轉換為大寫:"<<str<<endl;
  13.     strlwr(str);
  14.     cout<<"轉換為小寫:"<<str<<endl;   
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     char str[50];
  8.     cout<<"輸入一字串: ";
  9.     cin.getline(str,50);
  10.     cout<<"你剛輸入的字串是: "<<str<<endl;
  11.     strupr(str);   
  12.     cout<<"轉換為大寫: "<<str<<endl;
  13.     cout<<"+*****************+"<<endl;
  14.     strlwr(str);   
  15.     cout<<"轉換為小寫: "<<str<<endl;
  16.     system("pause");     
  17.     return 0;   
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char str[1000];
  7.     cout<<"輸入一字串: ";
  8.     cin.getline(str,1000);
  9.     cout<<"你剛剛輸入的字串是:"<<str<<endl;
  10.     cout<<"大寫:"<<strupr(str)<<endl;
  11.     cout<<"小寫:"<<strlwr(str)<<endl;
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.    
  8.     char str[50];
  9.     cout<<"輸入一字串"<<endl;   
  10.     cin.getline(str,50);   
  11.     cout<<"你剛剛輸入的字串轉換為大寫是"<<strupr(str)<<endl;
  12.     cout<<"你剛剛輸入的字串轉換為小寫是"<<strlwr(str)<<endl;
  13.    
  14.    
  15.    system("pause");
  16.    return 0;


  17. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.    char str[50];
  8.    cout<<"輸入一字串: ";
  9.    cin.getline(str,50);
  10.    cout<<"你剛剛輸入的字串是: "<<str<<endl;
  11.    strupr(str);
  12.    cout<<"轉換為大寫: "<<str<<endl;
  13.    strlwr(str);
  14.    cout<<"轉換為小寫: "<<str<<endl;
  15.    
  16.    system("pause");
  17.    return 0;
  18. }
複製代碼

TOP

返回列表