top1编程
← 返回题目
题解

【入门】输出字符的ascii码

1 条题解

  • 0
    @ 2026-7-29 0:18:37
    #include <iostream>
    using namespace std;
    
    int main() {
        // 定义一个字符变量存储输入
        char ch;
        
        // 从键盘读取一个字符(注意:cin 读取字符时会自动跳过空格/换行)
        cin >> ch;
        
        // 将字符强制转换为整数(即对应的 ASCII 码)并输出
        cout << (int)ch << endl;
        
        return 0;
    }
    
    • 1