程序不在控制台中显示

时间:2014-03-17 18:46:47

标签: c++ xcode

我使用的是最新版本的Xcode,当我运行程序时,我无法在控制台中看到任何内容。我尝试了各种各样的方法,比如重新打开控制台,我真的需要帮助。这是程序:

//
//  main.cpp
//  Quiz Game
//
//  Created by MS Student on 3/10/14.
//  Copyright (c) 2014 BrenGames. 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<<"Brendan 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();
    };

}

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

语法正确:

while(contition)
{
  //do something
}
你的代码中的

(在元代码中):

  

1 = 1,什么都不做

你可以看到&#34;什么都不做&#34;因为你放了一个&#39 ;;&#39;在&#39; {&#39;。

之后

它被称为无限循环,你永远不会追踪while条件,因为它总是被验证。

此外,你为什么在main中添加#include?