本篇介绍C++判断语句,与C# Java基本无异。下面举例说明
/*
* Author:W;
* 判断
* 1.if..else
* 2.switch
*/
//引入头文件:头文件包含了程序中必需的或有用的信息【单行注释】
#include <iostream>
//命名空间使用
using namespace std;
//main程序执行入口函数
int main()
{
//if..else语句
cout << "===if..else语句===" << endl;
int total = 5;
if (total > 7)
{
cout << "total > 7" << endl;
}
else
{
cout << "total < 7" << endl;
}
//switch语句
cout << "===switch 语句===" << endl;
int type = 3;
switch (type)
{
case 1:
break;
case 2:
break;
case 3:
cout << "case 3" << endl;
break;
case 4:
break;
default:
break;
}
}
运行结果如下: