Quote:Original post by ZahlmanQuote:Original post by agm_ultimatexQuote:Original post by Portmanteau
AFAIK, the STL string class does not have an at method, just an [] operator.
visual studio brings up the at in the list when you type string1. However using [] also gives me the error: Error 2 error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const char'
Show the part of the code where you declare the variables you're using here.
I added [0] to letter in the if comparison, that fixed the error. Never the less, heres my current code and variable declarations.
void Game::Play(){ DrawHangMan(0); std::string words[10]; words[0] = "mitsubishi"; words[1] = "georgian"; words[2] = "battlecruiser"; words[3] = "ubuntu"; words[4] = "paladin"; words[5] = "ferrari"; words[6] = "macintosh"; words[7] = "canada"; words[8] = "zeitgeist"; words[9] = "windows"; srand(time(0)); int wordNum = (rand() %10); const std::string theWord = words[wordNum]; int numOfTries = 0; std::string displayWord(theWord.size(), '-'); std::string lettersUsed = ""; do { std::cout << "Word to guess: " << displayWord << "\n"; if(lettersUsed.size() > 0) { std::cout << "You have used letters: " << lettersUsed << "\n"; } std::string letter; std::getline(std::cin, letter); //if letter is found if(theWord.find(letter) != std::string::npos) { if(lettersUsed.find(letter) == std::string::npos) { std::cout << "You got a letter in the word.\n"; for(unsigned int i = 0; i < theWord.length(); i++) { if(theWord == letter[0]) { displayWord += letter; } else if(theWord != "-") { displayWord += "-"; } } } } else { std::cout << "That letter is not in the word.\n\n"; numOfTries++; DrawHangMan(numOfTries); } lettersUsed += letter; std::vector<std::string>::iterator it; }while(displayWord != theWord && numOfTries < 6); std::cout << "You got it!\n";}