平时并不关心一个字符的 ASCII 是多少,不过,最近,在看一些关于哈希表的东西,ASCII 码就显得特别重要,再后来,我就看见了这个函数 toascii ,下面,我们首先看看这个函数的原型:
extern int toascii(int c)
可见,我需要传递一个 int 类型的参数给它,也就是一个字符,这个函数的返回值是一个整数值,当然,它代表的就是 0--255 之间的某一个数值,与你传递的那个字符的 ASCII 对应,下面,就随便写点东西吧:
#include <iostream>
#include <cstring>
#include <ctype.h>
using namespace std;
void to_asscii(char *str);
int main(int argc, char **argv, char **environ)
{
char *str = "dlutbrucezhang";
to_asscii(str);
return 0;
}
void to_asscii(char *str)
{
int len = strlen(str);
for (int i = 0; i != len; i++)
{
cout<<str[i]<<" : "<<toascii(str[i])<<endl;
}
return;
}
运行的结果如下图所示: