I am having trouble with cstrings. I have worked with strings, but never cstrings. I'm trying to make something where the user is prompted to enter in their gender, and then if it is male the program will output male and vice versa.
a is an array of char; a will devolve to a char-pointer, pointing at a[0], anywhere it can that you use it.
a[i] is a single char. One char.
"male" is a string literal, which returns a pointer to the 'm' somewhere in memory. So this:
a[i]=="male" is an attempt to compare a single char value with a char-pointer value. Hopefully, it's clear to you that that won't work.
You might think this would do it:
if (a == "male")
but that is comparing a pointer to a[0] to the pointer to the 'm', and since a[0] and the 'm' are in different places in memory, you'd be comparing different pointers with different values. Again, that's not right.
In this case, what needs to happen is a[0] needs to be compared to the character m, and then a[1] to the character a, and so on. This is a pain to write, so we have the function strcmp to do it for us. It lives in <cstring>. Please look it up.