Help Please! STRCMP?

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* 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>

using namespace 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;
}


Thanks
is "Cannot covert STD::STRING into Const Char*" an compiling error or warning?
You don't need to use strcmp with std::strings, you can just use == and it will have the desired behavior.
Its a compiler error. And thanks guys and draco I'll try that. Thanks.
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.
Thanks William. That was very helpful! :)
That makes sense if it a compiling error. Just follow other 2 guys' suggestions.
What is Sanfrisco?
thanks Eric, yeah, their suggestions did work :).
Lol Disch. Oh yeah I mispelled it; I meant San Francisco, as you would already have guessed haha.
Topic archived. No new replies allowed.