关于getline的奇怪问题,莫名其妙地不执行
一个很简单的小程序,就是让用户输入一些变量的初始值。可是运行的时候
getline(cin,adjective);
这一语句却不执行,不知道为什么。百思不得其解!
getline
#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
const int lowerBound = 100;
const int upperBound = 200;
int main()
{
string instructor_name, your_name,food,adjective,
color, animal;
int number;
/*cout<<"Your instructor's name:\n";
getline(cin,instructor_name);
cout<<instructor_name<<endl;
cout<<"Your name:\n";
getline(cin,your_name);
cout<<your_name<<endl;
cout<<"Your favourite food:\n";
getline(cin,food);
cout<<food<<endl;
*/
do
{
cout<<"A number between "<<lowerBound<<" and "<<upperBound<<":\n";
cin>>number;
}while(number <lowerBound || number >upperBound);
cout<<number<<endl;
cout<<"Input an adjective (please note that this programme is unable to check the CIXING of this word!)\n";
getline(cin,adjective);
cout<<adjective<<endl;
cout<<"Input a colour:\n";
getline(cin,color);
cout<<color<<endl;
cout<<"Input an animal:\n";
getline(cin,animal);
cout<<animal<<endl;
cout<<"Press any key to exit:";
getchar();
}