开发者

C++: Infinite loop with a simple menu selection

开发者 https://www.devze.com 2023-01-28 10:58 出处:网络
The script I am working on is over a page long, so I am going to link it (one simple file): http://pastebin.com/7BVHmQGp

The script I am working on is over a page long, so I am going to link it (one simple file):

http://pastebin.com/7BVHmQGp

I apologize for that. My p开发者_如何学Pythonroblem is I get into an infinite loop in my code, for example after I select 1 or 2 for encrypting/unencrypting it lets me enter the word, and when I next enter the "shift" for the cipher it runs an infinite loop of the menu.

I had tried for so many hours to debug this, I thought it was a problem with cin, for example when you enter an invalid choice it just throws an infinite loop/

What seems to cause the infininte loops?


I think you should be ignoring the newline character instead of a space

I tried with the following and it works on VS2010

    cin.ignore(1, '\n');
    getline(cin, input);


Try cin.clear, I believe you are constantly reading your initial input character.

    cin >> selection;
    cin.clear(); 


This page should explain all you need to know.

0

精彩评论

暂无评论...
验证码 换一张
取 消