ningún operador “<<" coincide con estos operandos

No tengo idea de lo que está pasando. Miré otras publicaciones que son similares a este problema, pero ninguna solución me ayudó hasta ahora. Aquí está el código con comentarios de las partes que dan errores. En un momento dice que! = No funciona y en el rest del código está diciendo que << no está funcionando.

#include  #include  #include  #include  #include  #include  using namespace std; //Hangman int main() { //setup vector words; words.push_back("GUITAR"); words.push_back("VIRGINIA"); words.push_back("LAPTOP"); words.push_back("WIFEY"); words.push_back("IPHONE"); srand(static_cast(time(0))); //randomly select a word random_shuffle(words.begin(), words.end()); const string THE_WORD = words[0]; const int MAX_WRONG = 8; //initialize wrong guesses int wrong = 0; string soFar(THE_WORD.size(), '-'); //initalize the word so far with dashes string used = " "; //initalize letters used cout << "Welcome to Hangman. Good luck!/n"; //game loop //continues until a player guesses the word or gets too many wrong guesses while ((wrong < MAX_WRONG) && (soFar != THE_WORD)) //ERROR on the "!=" { cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n"; cout << "\nYou've used the following letters:\n" << used << endl; //ERROR on "<<" between the string and used cout << "\nSo far, the word is:\n" << soFar << endl; //ERROR on "<<" between the string and soFar //recieve the player's guess char guess; cout <> guess; guess = toupper(guess); //makes the guess uppercase since the secret word is uppercase while (used.find(guess) != string::npos) { cout << "\nYou've already guessed " << guess << endl; cout <> guess; guess = toupper(guess); } used += guess; if (THE_WORD.find(guess) != string::npos) { cout << "That's right! " << guess << " is in the word.\n"; //updated 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; //ERROR on "<> pause; //this is here just so my compiler will stay open so I can see what's going on return 0; } 

Si desea usar std::string manera confiable, debe #include .

No está incluyendo el encabezado estándar.

No tuvo la suerte de que algunas de las definiciones pertinentes se pusieran accidentalmente a disposición por los otros encabezados estándar que incluyó … pero el operator<< no fue.

Parece que estás comparando cadenas incorrectamente. Para comparar una cadena con otra, use la función std::string::compare .

Ejemplo

  while ((wrong < MAX_WRONG) && (soFar.compare(THE_WORD) != 0))