菜鸟请教输入问题
#include<iostream>
using namespace std;
void n_chars(char c, int n);
int main()
{
int times=0;
char ch;
cout << "Enter a character : ";
cin >> ch;
while (ch != 'q')
{
cout << "Enter an integer : ";
cin >> times;
n_chars(ch, times);
cout << "\n Enter another character or press the q-key to quit \n";
cin >> ch;
cout << times << endl;
}
cout << "The value of times is " << times << ".\n";
cout << "Bye !";
cin.get();
return 0;
}
void n_chars(char c, int n)
{
while (n-- > 0)
{
cout << c;
}
}
如果输入cout << "Enter an integer : "; cin >> times; 给times一个字符输入就死循环了,想知道为什么。谢谢了。