It keeps saying "Cannot covert STD::STRING into Const Char*". But my strcmp function is just comparing the two not converting anything! What's wrong with this thing?
/* In this game, there will be a ninja.
He will kill the dark evil Ninja. He will go to
New York, L.A, or Sanfrisco to search for the evil Ninja.
When he goes to the correct one, he will battle the evil Ninja.
*/
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
usingnamespace std;
int main()
{
string sPlayAgain;
string *pPlayAgain = &sPlayAgain;
do
{
cout << "\nWould you like to play again? Please type Yes or No\n";
cin >> sPlayAgain;
}while(strcmp(*pPlayAgain,"Yes")==0);
return 0;
}
first of all, the compiler HAS TO change the string to a char * because to compare two things they need to be the same type. If one type is different, it attempts to convert it. strcmp needs only char * so to use it properly you need to do it this way. the c_str() function is apart of string and converts the string to a const char * so you can use it with some of the older functions.
strcmp(sPlayAgain.c_str(),"Yes");
Like it was said earlier, strings have a much easier way of handing comparing of strings.
if(sPlayAgain == "Yes")
Remember that all of this is case sensitive so you may also want to convert the strings to lowercase first before comparing but that is off the subject.
Also your string pointer is useless here, you can take out that variable all together.