C++第三題:產生輸入字元相對應之 ASCII 碼。
本帖最後由 stephen 於 2010-2-20 11:02 編輯
C++第三題:產生輸入字元相對應之 ASCII 碼。
程式說明:
1. 資料型態的轉換方式 : (欲轉換的型態)欲轉換的變數。
ex : (int)user_char; // 轉換前為 char(字元)型態,轉換後為 int(整數)型態。- /*產生輸入字元相對應之 ASCII 碼。 */
- #include <iostream>
- using namespace std;
- int main(void){
-
- char char_user; /* char 為字元的型態 */
- cout << "Please enter an Character : " << endl;
- cin >> char_user;
- cout << "the ascii of " << char_user << " is " << (int)char_user << endl;
- system("pause");
- return 0;
- }
複製代碼 |