vendredi 4 novembre 2016

String pre-definition in .h file and using it to filter user input

Consider the following situation:

#define YES "y"||"Y"||"yes"||"Yes"||"YES"
#define NO "n"||"N"||"no"||"No"||"NO"

With macros being used at the user input.

FRW::writeLine(PLAY_AGAIN);
    latestResponse = FRW::getUserInput();
    if (latestResponse == YES)
    {
        retry = false;
    }
    else if (latestResponse == NO)
    {
        retry = true;
    }

I am aware that this is wrong and I should actually use...

#define YES latestResponse == "y"|| latestResponse == "Y"|| latestResponse == "yes"|| latestResponse == "Yes"|| latestResponse == "YES"

... and checking as

 if (latestResponse == YES)
    {
        retry = false;
    }
    else if (latestResponse == NO)
    {
        retry = true;
    }

Please, can somebody recommend any other way of implementing string macros? Or should I stay this way?

Aucun commentaire:

Enregistrer un commentaire