#include<iostream>
using namespace std; bool user_says_yes()
{
int c;
bool initial_response = true;
while (c != 'y' && c != 'Y' && c != 'n' && c != 'N')
{ // Loop until an appropriate input is received.
if (initial_response)
cout << " (y,n)? " << flush; else
cout << "Respond with either y or n: " << flush;
c=cin.get();
initial_response = false;
}
return (c == 'y' || c == 'Y');
}
int main(){
cout<<user_says_yes();
return 0; }
上面这个程序运行正常,可是把c=cin.get();改成cin>>c;后运行却崩溃了;
谁能帮我解答一下为什么啊???
using namespace std; bool user_says_yes()
{
int c;
bool initial_response = true;
while (c != 'y' && c != 'Y' && c != 'n' && c != 'N')
{ // Loop until an appropriate input is received.
if (initial_response)
cout << " (y,n)? " << flush; else
cout << "Respond with either y or n: " << flush;
c=cin.get();
initial_response = false;
}
return (c == 'y' || c == 'Y');
}
int main(){
cout<<user_says_yes();
return 0; }
上面这个程序运行正常,可是把c=cin.get();改成cin>>c;后运行却崩溃了;
谁能帮我解答一下为什么啊???