Hey guys,
I searched before I decided to post but to no avail. Basically, my situation is that I'm learning C++ through a really informative book called Beginning C++ Game Programming by Michael Dawson. I just reached a section where the author demonstrates how to create the source code for a game of Hangman. I copied his version of the game word for word and tried to compile it (I got a used version of the book, so the CD that contains all the original files discussed in the book is not in my possession), but it gave me quite a few compile errors--which may be due to syntax errors, but I can't seem to locate any.
This is what the program looks like:
Code:
//Hangman
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cctype> // cctype is part of the standard lib and it includes functions for converting
//characters to uppercase, which is used in order to compare individual letters
int main()
{
//setup
const int MAX_WRONG = 8; //max number of incorrect guesses
vector<string> words; //collection of possible words to guess
words.push_back("CONGLOMERATION");
words.push_back("TELEOLOGY");
words.push_back("TACITURN");
srand(time(0));
random_shuffle(words.begin(), words.end()); //words are shuffled so index position '0' will be random
const string THE_WORD = words[0];
int wrong = 0;
string soFar(THE_WORD.size(), '-');
string used = "";
cout << "Welcome to Hangman!\n";
while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
{
cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n";
cout << "\nYou've used the following letters:\n"; << used << endl;
cout << "\nSo far, the word is:\n" << soFar << endl;
char guess;
cout << "\n\nEnter your guess: ";
cin >> guess;
guess = toupper(guess); //make uppercase since secret word is in uppercase
while (used.find(guess) != string::npos)
{
cout << "\nYou've already guess " << guess << endl;
cout << "Enter your guess: ";
cin >> guess;
guess = toupper(guess);
}
used += guess;
if (THE_WORD.find(guess) != string::npos)
{
cout << "That's right! " << guess << " is in the word.\n";
//update soFar to include newly guessed letter
for (int i = 0; i < THE_WORD.length(); ++i)
if (THE_WORD[i] == guess)
soFar[i] = guess;
}
else
{
cout << "Sorry, " << guess << " isn't in the word.\n";
++wrong;
}
}
//shut down
if (wrong == MAX_WRONG)
cout << "\nYou've been hanged!";
else
cout << "\nYou guessed it!";
cout << "\nThe word was " << THE_WORD << endl;
system("Pause");
}
And here's the error it's giving me: "`vector' undeclared (first use this function) ". I'm using Dev-C++ version 4.9.9.2. I can't find what the error is, I'm sure it is something really simple that I'm just not seeing. Any help would be very much appreciated from this noob programmer!
Thanks!