简体   繁体   English

带有枚举的C ++ Visual Studio调试器错误

[英]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. 我正在构建一个牛与牛游戏(必须通过命令提示符猜测一个字)我在Microsoft Visual Studio 2017中遇到问题,我正在使用一个枚举检查输入错误。应该被认为是像Word_Length这样的调试器中的错误,或者如果确定,则应该显示OK。 Then when I run the debugger, instead of displaying a message like OK or Word_Length it displays some numbers. 然后,当我运行调试器时,不显示诸如OK或Word_Length之类的消息,而是显示一些数字。

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. 还是对VS。我觉得很奇怪,因为我正在与C ++课程一起做这件事,因此代码应该没问题。 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. 这是在main.cpp中,然后将其标记为要调试。

EGuessStatus Status = BCGame.checkGuessValidity(Guess);

In this situation the word is 'planet' and as you can see, the debugger spews out weird numbers. 在这种情况下,单词是“ planet”,如您所见,调试器发出了奇怪的数字。

This is an image of the debugger once I input 'planet' which is supposed to be correct 这是我输入正确的“ planet”后调试器的图像

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. 我使用std :: map并将人类可读的消息映射到每个枚举。 You can then do 'std::string msg = lookup_map_.at(enum);'. 然后,您可以执行“ 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! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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