Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 堆叠开关语句c++;_C++ - Fatal编程技术网

C++ 堆叠开关语句c++;

C++ 堆叠开关语句c++;,c++,C++,我只是想知道我们是否可以将switch case语句堆叠起来,例如,一个案例导致另一个案例变成另一个案例等等。我目前正在计划如何制作我的项目,但我需要确认这是否可行。好吧,我将添加一个有趣的方法来完成它 警告:我不会真的这样做,这只是一种做你喜欢的事情的方式 #include<iostream> int main() { int foo = 0; switch ( foo ) { case 0 : goto that;

我只是想知道我们是否可以将switch case语句堆叠起来,例如,一个案例导致另一个案例变成另一个案例等等。我目前正在计划如何制作我的项目,但我需要确认这是否可行。好吧,我将添加一个有趣的方法来完成它

警告:我不会真的这样做,这只是一种做你喜欢的事情的方式

#include<iostream>

int main()
{
    int foo = 0;
    switch ( foo ) 
    {
    case 0 :
        goto that;
        break;
    case 1 :
that :
        std::cout << 'b';
        goto theOther; 
        break;
    case 2 :
theOther :
        std::cout << 'a';
        goto andAnother;
        break;
    case 3 :
andAnother :
        std::cout << 'r';
        break;
    }
    return 0;
}
#包括
int main()
{
int-foo=0;
开关(foo)
{
案例0:
转到那个;
打破
案例1:
即:

std::不能用代码来解释你的意思。如果你省略了
中断;
,你可以将一个开关嵌入另一个开关。发生了什么事?如果你与我们共享你的代码,我们可能会帮助你修复它。嵌套的
开关…case
结构是合法的,如果你是这个意思。DoeWhat’你的项目取决于这是否可能?你永远不应该为严肃的事情做那件事。我同意。但那看起来太有趣了,不去尝试。太好了。
#include<iostream>

int main()
{
    int foo = 0;
    switch ( foo ) 
    {
    case 0 :
    case 1 :
        std::cout << 'b';
    case 2 :
        std::cout << 'a';
    case 3 :
        std::cout << 'r';
    }
    return 0;
}
#include<iostream>

int main()
{
    int foo = 0;
    switch ( foo ) 
    {
    case 0 :
        goto andAnother; 
        break;
    case 1 :
that :
        std::cout << 'b'; 
        break;
    case 2 :
theOther :
        std::cout << 'a';
        goto that;
        break;
    case 3 :
andAnother :
        std::cout << 'r';
        goto theOther;
        break;
    }
    return 0;
}