asc and chr equivalent in C/C++

前端 未结 3 1941
囚心锁ツ
囚心锁ツ 2021-01-13 12:44

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 a

3条回答
  •  无人共我
    2021-01-13 13:37

    In C and C++, if you use a character enclosed by '' and not "" it means you are dealing with its raw binary value already.

    Now, in C and C++, "0" is a literal two byte null-terminated string: '0' and '\0'. (ascii 48 ascii 0)

    You can achieve what you want by using var[0] on a "" null-terminated string or use one of the conversion routines. (atoi() in C, stringstream lib in C++)

提交回复
热议问题