C++ default 关键字
定义和用法
default
关键字用于指定 switch
语句中的默认代码块,即当 switch
中没有匹配的 case
时要运行的代码。
实例
指定当 switch
块中没有匹配的 case
时要运行的代码:
int day = 4; switch (day) { case 6: cout << "Today is Saturday"; break; case 7: cout << "Today is Sunday"; break; default: cout << "Looking forward to the Weekend"; }
相关页面
教程:C++ switch