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

标签 c++ visual-studio unreal-engine4

我正在尝试学习 C++ 类(class)以更熟悉该语言和虚幻引擎。但是,现在每当我启动程序时,控制台窗口都会立即关闭。我已经尝试修复子系统的问题,并且看到一些无法关闭窗口的脏代码,但我想知道如何在不尝试寻找奇怪的环球航行的情况下解决问题。

/* 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;
}

最佳答案

如果您将输出重定向到文本文件,那么它不会在执行后停止。您可以在调试部分检查项目设置。

关于c++ - (C++) 即使我在 Visual Studio 中按 CTRL + F5,控制台窗口也会立即关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48875735/

相关文章:

c++ - 拖动 3D 控制杆(基于方向和视角)

c++ - std::vector push_back(Object()) 和 push_back(new Object()) 的区别?

c++ - 什么是用 C++ 开发 Web 服务的好平台?

python - Visual Studio CL.exe 找不到 python.h

c++ - 作为指针的 const 成员函数的返回值的属性是什么?

unreal-engine4 - 我可以使用虚幻引擎 4 编写软件而不从源代码编译虚幻引擎 4 吗?

c++ - 我应该如何有条件地启用构造函数?

c++ - 使用 std::ios_base::Init 正确初始化全局变量

visual-studio - 项目属性未打开 - "There are no property pages for the selection"

c# - 重命名操作被取消或无效