以下为个人学习笔记整理。参考书籍《C++ Primer Plus》
# 分支语句和逻辑表达式
# if 语句
| int i = 1; |
| if (i > 0){ |
| |
| }else if (i == 0){ |
| |
| }else{ |
| |
| } |
# 逻辑表达式
# 字符函数库 cctype
ispunct(char)
:判断字符是否为标点。isdigits(char)
:判断字符是否为数字。isalpha(char)
:判断是否为字母。isspace(char)
:判断是否为空白。- ...
# ?: 运算符
| int result = 5 > 3 ? 1 : 0 |
# switch 语句
| int select = 1; |
| switch (select) { |
| case 1: cout << "select = 1" << endl; break; |
| case 2: cout << "select = 2" << endl; break; |
| case 3: cout << "select = 3" << endl; break; |
| case 4: cout << "select = 4" << endl; break; |
| default: cout << "select not in (1,2,3,4)" << endl; |
| } |