1、输入一个ASCII码,输出对应的字符

#include <iostream>
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        cout << (char)n << endl;
    }
    return 0;
}

2、输入一个字符,输出相对应的ASCII码

#include <iostream>
using namespace std;
int main()
{
   char k;
    while (cin >> k)
    {
        cout << (int)k << endl;
    }
    return 0;
}

3、字符之间相加减

已知a,b为字符,

a-b即为a的ascii码减去b的ascii码,记为int k=a-b;

结果K为ascii码;

char(k)为字符;

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐