2_22a.cpp

来自「经典vc教程的例子程序」· C++ 代码 · 共 34 行

CPP
34
字号
// Using the switch multiple-selection structure
#include <iostream.h>

main()
{
   int choice;  // user's request
       
   cout << "Enter a choice:\n"
        << "   1 to print the string One\n"
        << "   2 to print the string Two\n"
        << "   3 to print the string Three\n? ";
   cin >> choice;

   switch ( choice ) {

      case 1:
         cout << "One\n";
         break;

      case 2:
         cout << "Two\n";
         break;

      case 3:
         cout << "Three\n";
         break;

      default:
         cout << "Invalid choice\n";
         break;
   }

   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?