-
Basic string question
I've got a basic string question that I'm sure the large majority of you will be able to answer, but I haven't found something similar on these boards after an hour that would fix my problem.
Code:
string position;
if (strcmp(position,"Home") == 0)
{
cout << "YES!!!!!";
}
... gives me the error "cannot convert `std::string' to `const char*' for argument `1' to ".
Any suggestions? Thanks.
-
The string container has an overloaded == operator that would work. Alternately, you could convert the string to a const char* using the c_str member function:
Either:
Code:
string position;
if ( position == "Home" )
{
cout << "YES!!!!!";
}
Or:
Code:
string position;
if (strcmp(position.c_str(),"Home") == 0)
{
cout << "YES!!!!!";
}
-
Sweet. It works perfectly. Thanks!!