C++進行字母大小寫轉換


#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

int main(void) {
    char x;

    cout << "請輸入一個字符:";
    cin >> x;
   //利用ASCII碼表中的字符排列規律進行字母的大小寫轉換
    if (x >= 'a' && x <= 'z') { //小寫字母
        x = x - 'a' + 'A';
    } else if (x >= 'A' && x <= 'Z') {
        x = x - 'A' + 'a';
    }

    cout << x << endl;

    system("pause");
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM