C++ 的 对char使用switch
等级 3154 次按键
char是整数类型,因此可以在switch中用字符字面量作case标签。grade为'B',所以输出“Good”。
C++ 代码
// 字符字面量使用单引号1char grade = 'B';// 把grade与每个字符标签比较2switch (grade) {3 case 'A': cout << "Excellent"; break; // 'B'匹配:输出Good,然后break跳出switch4 case 'B': cout << "Good"; break; // 没有default,所以其他等级什么都不会输出5 case 'C': cout << "Fair"; break;6}// 换行7cout << endl;运行结果
Good
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 C++ 代码中需要输入的符号及其出现次数。
;× 8'× 8<× 8"× 6:× 3(× 1)× 1{× 1}× 1=× 1