问题描述
当我在互联网上通过源代码搜索新信息时,
我看到有人将 goto
用于一个变量,而这个变量与一个 cout
语句,与 std::cout
中的相同。
他写了a:cout
。
你能帮我找到这个函数的名字吗?
void Main_Menu() {
int i;
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t HOSPITAL MANAGEMENT SYstem \n\n";
cout << "\n\n\t\t\t\t\t\tPlease,Choose from the following Options: \n\n";
cout << "\t\t\t\t\t\t _________________________________________________________________ \n";
cout << "\t\t\t\t\t\t| |\n";
cout << "\t\t\t\t\t\t| 1 >> Add New Patient Record |\n";
cout << "\t\t\t\t\t\t| 2 >> Add Diagnosis information |\n";
cout << "\t\t\t\t\t\t| 3 >> Full History of the Patient |\n";
cout << "\t\t\t\t\t\t| 4 >> information About the Hospital |\n";
cout << "\t\t\t\t\t\t| 5 >> Exit the Program |\n";
cout << "\t\t\t\t\t\t|_________________________________________________________________|\n\n";
a: cout << "\t\t\t\t\t\tEnter your choice: ";
cin >> i;
if (i > 5 || i < 1) {
cout << "\n\n\t\t\t\t\t\tInvalid Choice\n";
cout << "\t\t\t\t\t\tTry again...........\n\n";
goto a;
} //if inputed choice is other than given choice
解决方法
没有变量 a
链接到 cout
。 a:
是一个标签,您可以使用 goto a;
跳转到该标签。代码也可以这样写
a:
cout << "\t\t\t\t\t\tEnter your choice: ";
cin >> i;
if (i > 5 || i < 1) {
cout << "\n\n\t\t\t\t\t\tInvalid Choice\n";
cout << "\t\t\t\t\t\tTry again...........\n\n";
goto a;
} //if inputed choice is other than given choice
有趣的旁注:为什么
void f()
{
http://stackoverflow.com
https://stackoverflow.com
}
有效的 C?因为 http
和 https
被视为标签,而 //
开始评论。