简体   繁体   中英

C++ Visual Studio Debugger Error with Enumeration

I'm building a bulls and cows game(have to guess a word through command prompt) I'm having a problem in Microsoft Visual Studio 2017 where I'm using an enum to check for input errors.If there is an error, there is supposed to be an error in the debugger like Word_Length or if its ok it should display OK. Then when I run the debugger, instead of displaying a message like OK or Word_Length it displays some numbers.

Could I be doing something wrong? Or is it VS.. I find it weird because I'm doing this alongside a c++ course so the code should be fine. Thanks for any help!

--Code--------

Here is where I declare the Enumeration

enum class EGuessStatus
{
    OK,
    Not_Isogram,
    Wrong_Length,
    Not_Lowercase
};

Here I say if the word length is not right, return the error

else if (Guess.length() != GetHiddenWordLength())   //if the word length is 
                                                    //wrong, return an error
    {
        return EGuessStatus::Wrong_Length;

    }

And then I say if the Guess is OK, return OK

else {      //otherwise, return ok
        return EGuessStatus::OK;
    }

And here it is in the main.cpp where I then mark it to debug.

EGuessStatus Status = BCGame.checkGuessValidity(Guess);

In this situation the word is 'planet' and as you can see, the debugger spews out weird numbers.

This is an image of the debugger once I input 'planet' which is supposed to be correct

I'm not sure I totally understand the question but it seems like you're trying to convert an enum (who's underlying type is an integer) into a string representation?

If so then you can use a lookup table. I use std::map and map off a human readable message to each of the enums. You can then do 'std::string msg = lookup_map_.at(enum);'.

Wow, I feel Dumb. On the debugger, I clicked Auto instead of locals. When I checked locals the proper response displayed! Thanks for your help though!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM