xcode 控制台中未显示程序

p1tboqfb  于 2023-01-06  发布在  其他
关注(0)|答案(2)|浏览(214)

我使用的是最新版本的Xcode,运行程序时在控制台中看不到任何内容。我尝试了各种方法,例如重新打开控制台,但我确实需要帮助。程序如下:

//
//  main.cpp
//  Quiz Game
//
//  Created by MS Student on 3/10/14.
//  Copyright (c) 2014. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{

#include <iostream>

    {
        int sa;
        sa=1;
        string answer;
        while (sa==1);
        cout<<"Welcome to:\n";
        cout<<"\n";
        cout<<"\n";
        cout<<"\n";
        cout<<"My Quiz Game!\n";
        cout<<"Be excited.\n";
        cout<<"\n";
        cout<<"Enter HELP to recieve instructions, or enter START to begin.\n";
        cout<<"Commands are case-sensitive, and you must press Enter after inputting you        choice.\n";
        cin>>answer;
        if (answer == "HELP") {
            cout<<"\n";
            cout<<"So, here's your help.\n";
            cout<<"Questions will be asked of you, and you, well, have to answer them.\n";
            cout<<"Should kind of be obvious.\n";
            cout<<"However, should you happen not to be me, or someone who has never used the C++ language before,\n";
            cout<<"you need to know a few things.\n";
            cout<<"Answers must be in all caps, and you must press Enter after typing your answer.\n";
            cout<<"If you don't know how to type, then, well, I don't know what to tell you.";
            return 0;
        }
        cin.get();
    };

}
ebdffaop

ebdffaop1#

while (sa==1);将运行一个无限循环,因为sa最初是1,这里有一个额外的;

fjnneemd

fjnneemd2#

纠正while语法:

while(contition)
{
  //do something
}

在您代码中(在元代码中):
只要1=1,则不执行任何操作
你可以看到“什么也不做”,因为你把一个';' after while而不是'{'。
这就是所谓的无限循环,你永远不会去后,虽然条件,因为它总是验证。
此外,为什么要在main中添加#include?

相关问题