How to compare two different data types

Dec 9, 2014 at 4:55am
I have to compare the contents of a char array to a string. I have to use an if statement to see if one of the characters of the array match one of the letters in the string. How do I go about this?
Dec 9, 2014 at 5:18am
Do you have to match only character or all of them?
If you have to match only one, use indexes like you do for arrays.
1
2
3
4
if (myString[0] == charArray[0])
{
    //do something
}


Edit: Be sure to not go out of bounds.
This isn't the only way to do it, just the first way I thought of.
Last edited on Dec 9, 2014 at 5:18am
Dec 9, 2014 at 5:27am
char array has characters that the user inputs through some kind of loop. The user is trying to guess a secret word which a string that is a global variable. Its actually the game Hangman. To give you an idea.
Dec 9, 2014 at 11:41am
First, what forces the use of a char array? One can do input to std::string too.

Second, perhaps: http://www.cplusplus.com/reference/string/string/find_first_of/
Topic archived. No new replies allowed.