3.4 字符型变量

[an error occurred while processing the directive]

字符型变量存放的是字符,字符指的是计算机字符集中的ASCII码。字符型变量只占一个字节。

定义字符型变量

char ch;

给字符变量赋值

ch='A';(字符型变量必须用单引号)

例子:

#include

using namespace std;

int main(){

char ch;

ch = 'A';

cout << ch << endl;

cout << (int)ch;

system("pause");

return 0;

}

输出:A 65

特殊字符

\a 铃声(警报声)

\b 回退

\f 换页

\n 换行

\r 按enter键

\t Tab键

\v 垂直制表

\' 单引号

\" 双引号

\? 问号

\\ 反斜杠

\000 八进制

\xhhh 十六进制

[an error occurred while processing the directive]
Copyright © 2088 米策网游动态中心-新游测试与公会争霸 All Rights Reserved.
友情链接