我在C++中有这段代码,我想知道如何编写一些替换Lua中的switch语句的代码,因为我遇到了很多问题,我需要使用这个语句.
int choice;
do// loop
{
cout<<"\n >>> The General Menu <<< \n";
cout << endl;
cout<< " press (1) to Add "<<endl;
cout<< " press (2) to Save "<<endl;
cout<< " press (3) to Quit " << endl;
cout<< endl;
cout<< "Enter your choice please (1/2/3): ";
cin>>choice;
switch(choice)
{
case 1:
add();
break;
case 2:
save();
break;
default:
cout<<" The program has been terminated "<<endl;
cout<<" Thank you! \n";
}
} while (choice != 3);
Run Code Online (Sandbox Code Playgroud)
该语句已在do..while循环中使用.