gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:26 25 4
gpt4 key购买 nike

我正在尝试学习 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com