My code is telling me string is an "Illegal use of this type as an expression"

I’m fairly sure I have Ben’s exact code copied, but the compiler says I have an error on line 19 that ‘std::string’: illegal use of this type as an expression
I really don’t have any idea what it’s telling me is wrong, here’s my code

#include <iostream>
#include <string>
using namespace std;

void PrintIntro();
string GetGuessAndPrintBack();


// Entry point for application
int main()
{
	PrintIntro();

	GetGuessAndPrintBack();

	GetGuessAndPrintBack();

	cout << endl;
	return 0;
}
// get a guess from player
string GetGuessAndPrintBack() {
	string Guess = "";
	cout << "Answer: ";
	getline(cin, Guess);
	// repeat guess back to them
	cout << "Your Guess was: " << Guess << endl;
	return Guess;
}

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

any help would be appreciated, thanks!

Turns out the error was a ghost of an error I had when my code was at a previous state, and running without debugging worked fine and the error was gone when I continued.

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

Privacy & Terms