搜索链接到 cout 的变量的名称!像一个:cout c++

问题描述

当我在互联网上通过源代码搜索新信息时, 我看到有人将 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 链接到 couta: 是一个标签,您可以使用 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?因为 httphttps 被视为标签,而 // 开始评论。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...