【问题标题】:searching for the name of a variable linked to a cout! like a:cout c++搜索链接到 cout 的变量的名称!像:cout c++
【发布时间】:2021-02-20 15:33:16
【问题描述】:

当我通过互联网上的源代码搜索新信息时, 我看到有人将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

【问题讨论】:

  • 您是在询问goto 和标签,因为这就是这段代码正在做的事情。
  • 顺便说一句,使用空格而不是制表符。一个制表符可以代表 8、3、4 或 2 个空格。一个制表符可能意味着间隔到下一个制表位(可能是间歇性的)。也可以忽略标签。

标签: c++ windows cout goto


【解决方案1】:

没有变量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 被视为标签,// 开始评论。

【讨论】:

  • 非常感谢兄弟
猜你喜欢
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 2016-08-25
  • 1970-01-01
相关资源
最近更新 更多