1

当我运行我的程序时,我在 eclipse CDT 上得到以下信息:

There are 11 sticks left.

3
Enter Move:*stopped,reason="end-stepping-range",frame={addr="0x004015b4",func="_fu4___ZSt3cin",args=[],file="..\src\PlayerUser\PlayerUser.cpp",fullname="C:\Users\...\Desktop\workspace_eclipse\StickGame\src\PlayerUser\PlayerUser.cpp",line="26"},thread-id="1",stopped-threads="all"

直到“进入移动”的所有内容都有意义,但其余的则没有。出现此问题后,它一直让我输入内容,但程序似乎被冻结了。

我有很多代码,所以这里只是相关的部分:

主功能:

int main() {
    int sticks = 10;

    PlayerUser u(sticks);
    PlayerComputer c(sticks);

    StickGame game (u, c);
    game.startGame(11);
    return 0;
}

函数:PlayerUser::getMove

int PlayerUser::getMove(int n_left){
int on = 0;

while(true){
    cout << "There are " << n_left << " sticks left." << endl;
    cout << "Enter Move:" << flush; //where error occurs 
    cin >> on;
    if(on <= 3 && on >= 1)
        break;
}

setMove(n_left, on);
return on;
}

据我所知,它似乎与“详细控制台模式”有关,但我不明白那是什么或如何解决它。

4

1 回答 1

1

每次我在cout之后使用cin时,我都会在调试器中遇到同样的问题,最后我通过添加<< endl;解决了这个问题 考特

bool isDone()
    {
        char c;
        cout << "Enter 'Y' if food is done:";
        cin >> c;
        return ((c == 'Y') || (c == 'y'));
    }

这会产生错误,例如:

*stopped,reason="end-stepping-range",frame=...

但这工作得很好:

bool isDone()
    {
        char c;
        cout << "Enter 'Y' if food is done:" << endl;
        cin >> c;
        return ((c == 'Y') || (c == 'y'));
    }
于 2013-06-19T09:35:51.860 回答