ASC和C / C CHR相当于++ [英] asc and chr equivalent in C/C++

查看:249
本文介绍了ASC和C / C CHR相当于++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好标题pretty多总结起来。我想用C ++中像ASC(0),并希望使该程序与平台无关的,所以不要想用48!任何帮助AP preciated。

Well the title pretty much sums it up. I want to use something like asc("0") in C++, and want to make the program platform independent so don't want to use 48! Any help appreciated.

推荐答案

您可以简单地使用单引号作字符常量:

You can simply use single-quotes to make a character constant:

char c = 'a';

字符类型的的数字类型,因此对于递增 CHR 当量。

The character type is a numeric type, so there is no real need for asc and chr equivalents.

下面是打印出一个字符串的字符值的一个小例子:

Here's a small example that prints out the character values of a string:

#include <stdio.h>

int main(int argc, char **argv) {
  char str[] ="Hello, World!";

  printf("string = \"%s\"\n", str);

  printf("chars = ");
  for (int i=0; str[i] != 0; i++) 
    printf("%d ", str[i]);
  printf("\n");

  return 0;
}

输出是:

string = "Hello, World!"
chars = 72 101 108 108 111 44 32 87 111 114 108 100 33 

这篇关于ASC和C / C CHR相当于++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆