struct pizza
{
char band[20];
int weight;
int radius;
};
int main()
{
pizza exp = new pizza;
cout << "radius: ";
cin >> exp->radius;
* cin.get();**
cout << "bands: ";
cin.get(exp->band,20);
cout << "weight: ";
cin >> exp->weight;
cout << exp->band << " " << exp->weight << " " << exp->radius <<endl;
delete exp;
return 0;
}
为什么要加cin.get()才行
cin.get()吃掉你输入的回车,否则下面就读取不到正确的数据
用getchar()也可以,功能都一样,吸收掉输入队列中的回车符,这样才能保证正确输入