昨天调试一个含有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