这是代码,当我添加另一种情况或默认情况时,会出现几个错误。我找不到任何基本错误,例如缺少分号左右,并且当我只有一个案例时,代码可以正常工作。我搜索了开关教程,但我没有发现任何关于向量和开关语句混合是一个问题。
int main()
{
int r;
while (cin >> r)
{
switch (r)
{
case 3:
int y = 0;
cout << "Please enter some numbers, and I will put them in order." << endl;
vector<int> nums;
int x;
while(cin >> x)
{
nums.push_back(x);
y++;
}
sort(nums.begin(), nums.end());
int z = 0;
while(z < y)
{
cout << nums[z] << ", ";
z++;
if(z > 23)
cout << "\n" << "User... What r u doin... User... STAHP!" << endl;
}
cout << "\n" << "You entered "<< nums.size() << " numbers." << endl;
cout << "Here you go!" << endl;
break;
//In the following line I get the "jump to case label" error.
//I use Dev C++ software.
case 4:
cout << "it works!!!" << endl;
break;
}
}
system ("PAUSE");
return 0;
}
我错过了什么?