一个小问题,作为开胃菜! #include<iostream>
using namespace std;
int main()
{
int temp;
cout<<"please input a number:"<<endl;
cin>>temp;
switch(cin){
default:
cout<<"the number is not 1 or 2"<<endll;
case 1:
cout<<"the number is 1 "<<endll;
case 2:
cout<<"the number is 2 "<<endll;
}
}
如果输入1的话,结果是the number is 1 the number is 2
如果输入3的话,结果是 the number is not 1 or 2 the number is 1 the number is 2
用断点跟踪了下
输入1的话,从case 1:执行
输入3的话从default:开始执行?
为什么?????? |