查看单个帖子
  #1 (permalink)  
旧 2007-11-15
c++primer c++primer 当前离线
初级会员
 
注册日期: 2007-04-14
帖子: 22
c++primer 正向着好的方向发展
眨眼 一个小问题,作为开胃菜!

#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:开始执行?
为什么??????
回复时引用此帖