字串的處理 (八) - ASCII碼與字元相互查詢
本帖最後由 tonyh 於 2014-1-4 15:25 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int option, ascii;
- char letter;
- re:
- cout<<"1-輸入ASCII碼查字元(1~127) 2-輸入字元查ASCII碼(任意) 3-結束"<<endl;
- cout<<"請選擇: ";
- cin>>option;
- switch(option)
- {
- case 1:
- cout<<"輸入ASCII碼: ";
- cin>>ascii;
- cout<<"ASCII: "<<ascii<<"所對應的字元為"<<char(ascii);
- break;
- case 2:
- cout<<"輸入字元: ";
- cin>>letter;
- cout<<"字元: "<<letter<<"所對應的ASCII為"<<int(letter);
- break;
- case 3:
- goto end;
- break;
- default:
- cout<<"輸入錯誤!"<<endl;
- }
- cout<<endl<<endl;
- goto re;
- end:
- system("pause");
- return 0;
- }
複製代碼 |