为什么不能输入标题??
#include<iostream>#include<string>
using namespace std;
class Publication{
protected:
string title;
float price;
public:
Publication(string ti,float pri):title(ti),price(pri)
{
}
void GetData(){
string tit;
float pri;
cout<<"输入标题:"<<endl;
getline(cin,tit);
cout<<"输入价格"<<endl;
cin>>pri;
Settitle(tit);
Set_price(pri);
}
void Settitle(string ti){
title=ti;
}
void Set_price(float pri){price=pri;
}
void Show(){
cout<<"标题:"<<title<<endl;
cout<<"价格:"<<price<<"元"<<endl;
}
~Publication(){
}
};
class Book:public Publication
{
protected:
int page;
public:
Book(string ti="",float pri=0,int pa=0):Publication(ti,pri),page(pa){
}
void GetData(){
Publication::GetData();
cout<<"输入页数:"<<endl;
int pa;
cin>>pa;
Set_page(pa);
}
void Set_page(int pa){
page=pa;
}
void Show(){
Publication::Show();
cout<<"页数:"<<page<<"页"<<endl;
}
~Book(){
}
};
class Tape:public Publication
{
protected:
float playtime;
public:
Tape(string ti="",float pri=0,float playt=0):Publication(ti,pri),playtime(playt){
}
void GetData(){
Publication::GetData();
cout<<"输入播放时间:"<<endl;
float playt;
cin>>playt;
playtime=playt;
}
void Show(){
Publication::Show();
cout<<"播放时间:"<<playtime<<"分钟"<<endl;
}
};
int main(){
cout<<"建立书籍"<<endl;
Book b1;
string str;
b1.GetData();
b1.Show();
// cout<<"重新输入标题:"<<endl; //有问题,不能重新输入标题
// getline(cin,str);
// b1.Settitle(str);
// b1.Show();
cout<<"建立磁带"<<endl;//也不能输入标题
Tape t1;
t1.GetData();
t1.Show();
return 0;
}