(C ++)即使我在Visual Studio中使用CTRL + F5,控制台窗口也会立即关闭

时间:2018-02-19 23:30:45

标签: c++ visual-studio unreal-engine4

我试图通过C ++课程来熟悉语言和虚幻引擎。但是,现在每当我启动程序时,控制台窗口立即关闭。我已经尝试修复子系统的东西了,我已经看到了一些不会关闭窗口的脏代码,但是我想知道如何解决问题而不试图找到奇怪的环球航行。

/* This is the console executable, that makes use of the BullCowClass
This acts as the view in a MVC pattern, and is responsible for all 
user interaction. For game logic see the FBullCow`enter code here`Game class.
*/

#include <iostream>
#include <string>
#include "FBullCowGame.h"

using FText = std::string;
using int32 = int;

void PrintIntro();
void PlayGame();
FText GetValidGuess();
bool AskToPlayAgain();


FBullCowGame BCGame; //instantiatiate a new game
// entry point for our application

int main() 
{


    bool bPlayAgain = false;
    do 
    {
        PrintIntro();
        PlayGame();
        bPlayAgain = AskToPlayAgain();
    } while (bPlayAgain == true);



    return 0;
}

void PrintIntro() 
{
    //introduce to game

    std::cout << "Welcome to Bulls and Cows" << std::endl;
    std::cout << "Can you guess the " << BCGame.GetHiddenWordLength() << " letter isogram I'm thinking of?\n";
    std::cout << std::endl;
    return;
}
void PlayGame() 
{
    BCGame.Reset();
    int32 MaxTries = BCGame.GetMaxTries();

    //looping for the numbert of turns asking for guesses
    for (int32 i = 1; i <= MaxTries; i++)   {// TODO change from FOR to WHILE
        FText Guess = GetValidGuess();


        // submit valid guess to the game and receive counts
        FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess);

        std::cout << "Bulls = " << BullCowCount.Bulls;
        std::cout << ". Cows = " << BullCowCount.Cows << "." << "\n\n";
    }

    // TODO summarize game here
}

//loop continually until the use gives a valid guess
FText GetValidGuess() // TODO change to GetValidGuess
{   
    EGuessStatus Status = EGuessStatus::Invalid_Status;
    do {
        //get a guess from the player
        int32 CurrentTry = BCGame.GetCurrentTry();

        std::cout << "Try " << CurrentTry << " What is your word guess: ";
        FText Guess = "";
        std::getline(std::cin, Guess);

         Status = BCGame.CheckGuessValidity(Guess);


        switch (Status)
        {
        case EGuessStatus::Wrong_Length:
            std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n";
            break;
        case EGuessStatus::Not_Isogram:
            std::cout << "Please enter an isogram.\n";
            break;
        case EGuessStatus::Not_Lowercase:
            std::cout << "Please enter your guess in lowercase letters.\n";
            break;
        default:
            return Guess;
        }
        std::cout << std::endl;
        {

        };
    } while (Status != EGuessStatus::OK); //keep looping until we get no errors

}
bool AskToPlayAgain() 
{
    std::cout << "Do you want to play again(y/n)? ";
    FText Response = "";
    std::getline(std::cin, Response);
    if (Response[0] == 'y') 
    {
        return true;
    }
    if (Response[0] == 'n') 
    {
        return false;
    }
    return false;
}

1 个答案:

答案 0 :(得分:0)

如果您将输出重定向到文本文件,则执行后它不会停止。您可以在Debugging Section下检查项目设置。