C ++:通过简单的菜单选择进行无限循环 [英] C++: Infinite loop with a simple menu selection

查看:190
本文介绍了C ++:通过简单的菜单选择进行无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的脚本超过一页,所以我要链接它(一个简单的文件):
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

对此我深表歉意.我的问题是我进入了代码的无限循环,例如,当我选择1或2进行加密/取消加密后,它使我可以输入单词,而当我下次输入密码的移位"时,它将运行一个无限循环.菜单.

I apologize for that. My problem 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.

我已经尝试了很多小时来调试它,我认为这是cin的问题,例如,当您输入无效的选择时,它只会引发无限循环/

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/

什么原因导致infininte循环?

What seems to cause the infininte loops?

推荐答案

我认为您应该忽略换行符而不是空格

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

我尝试了以下方法,并且可以在VS2010上使用

I tried with the following and it works on VS2010

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

这篇关于C ++:通过简单的菜单选择进行无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆