Const help Error

Main.cpp:

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

void PrintIntro();
void PlayGame();
std::string GetGuess();
bool AskToPlayAgain();
FBullCowGame BCGame;

// the entry point for our application
int main()
{
	bool bPlayAgain = false;
	do {
		PrintIntro();
		PlayGame();
		bPlayAgain = AskToPlayAgain();
	} while (bPlayAgain);

	return 0; // exit the application
}



// introduce the game
void PrintIntro()
{
	constexpr int WORLD_LENGTH = 9;
	std::cout << "Welcome to Bulls and Cows, a fun word game.\n";
	std::cout << "Can you guess the " << WORLD_LENGTH;
	std::cout << " letter isogram I'm thinking of?\n";
	std::cout << std::endl;
	return;
}


void PlayGame()
{
	// loop for the number of turns asking for guesses
	int MaxTries = BCGame.GetMaxTries();
	std::cout << MaxTries << std::endl;
	constexpr int NUMBER_OF_TURNS = 5;
	for (int count = 1; count <= NUMBER_OF_TURNS; count++) {
		std::string Guess = GetGuess();
		std::cout << "Your guess was: " << Guess << std::endl;
		std::cout << std::endl;
	}
}


std::string GetGuess()
{
	// get a guess from the player
	int CurrentTry = BCGame.GetCurrentTry();
	std::cout << CurrentTry << ".Try ";
	std::cout << "Enter your guess: ";
	std::string Guess = "";
	getline(std::cin, Guess);
	return Guess;
}

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

FBullCowGame.h:

#pragma once
#include <string>
class FBullCowGame {
public:
	int GetMaxTries() const;
	int GetCurrentTry() const;
	bool IsGameWon() const;
	
	bool CheckGuess(std::string); //is guess valid?
	void Reset();


private:
	int MyCurrentTry = 1;
	int MyMaxTries = 5;
};

FBullCowGame.cpp:

#include "FBullCowGame.h"

int FBullCowGame::GetMaxTries() const { return MyMaxTries; }
int FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }

void FBullCowGame::Reset()
{
	return;
}

bool FBullCowGame::IsGameWon() const
{
	return false;
}

bool FBullCowGame::CheckGuess(std::string)
{
	return false;
}

Error:

1>------ Build started: Project: ConsoleApplication6, Configuration: Debug Win32 ------
1>pch.cpp
1>ConsoleApplication6.cpp
1>FBullCowGame.cpp
1>c:\users\uporabnik\source\repos\consoleapplication6\consoleapplication6\fbullcowgame.cpp(20): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add ‘#include “pch.h”’ to your source?
1>Generating Code…
1>Done building project “ConsoleApplication6.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I found something that might help with this:

I was running into some similar problems when I generated an empty project and then set it to console when I was using VS 2017. I got around this by creating a non-empty console project in Visual Studio and adding my files to it. This is how my overall project looks like now:
image

Here also is the top of my header for my main.cpp file:

#include "stdafx.h"
#include <iostream>
#include <string>
#include "main.h"

It is possible that if you go with the general setup (i.e. include stdafx.h in your headers) your header compiler error will go away (like the top answer in the stackoverflow.com link I sent you seemed to indicate).

Good luck!

I fixed it with disabling it, thank you for your help

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms