昨天调试一个含有cin函数的程序,在键盘输入竟然不可见?今天解决了问题,分享一下cin函数调试过程。
代码例子:
#include "stdafx.h"
#include <iostream>
#include <iostream>
int main()
{
using namespace std;
{
using namespace std;
char ch1[10],ch2,ch3[10],ch4[10];
cout << "Input a string:";
cin.get(ch1,5);
ch2 = cin.get();
cout << ch1 << " " << int(ch2);
cout << "Input a string:";
cin.get(ch1,5);
ch2 = cin.get();
cout << ch1 << " " << int(ch2);
return 0;
}
1.设置断点,开始调试:
点击左侧深色的边框,设置改行为断点,快捷键F5开始调试,F10逐步调试,黄色意味着暂停,此时弹出输入框。
2.cin逐步调试:
F10继续逐步调试,语句cout << "Input a string:";运行,同时,在cin.get(ch1,5);暂停,如黄色箭头。
此时,我们发现在键盘上输入,竟然没有反应??????
怎么回事?
由于程序暂停于cin.get(ch1,5);,而并未运行。继续按F10,再输入就可见了。输入12345[Ent

本文介绍了在调试含有cin函数的C++程序时遇到的键盘输入不可见问题及其解决方法。通过设置断点、逐步调试,发现cin.get()会暂停程序执行,导致键盘输入暂不显示。解决办法是在cin.get()后继续执行,即可看到输入。同时推荐了理解cin.get()用法的相关资源。
最低0.47元/天 解锁文章
5108

被折叠的 条评论
为什么被折叠?



