mercredi 17 février 2021

Convert string to char in C++

I wrote a code that can find a secret word only by guessing the letters with a variable of type char(not a tab).

Now, I want to add the possibility for the player to be able to either enter a letter as before, or enter the word directly. My problem is that if I change the type of the variable to string, nothing works anymore.

So, I was wondering if it was possible to create a new string variable that will get what the player enters (we will call it test):

if the test size> 1, it means that the player wants to guess the whole word and therefore I compare test to the word which was to be guessed.

Otherwise it means that the test size = 1 and in this case my goal would be to convert it to type char and assign its value to my variable of type char which already exists so as not to touch the rest of the program .

Thank you in advance for your help.

Aucun commentaire:

Enregistrer un commentaire