最近学到派生类,有道题目要求在基类和派生类中各写一个函数GetData()来从键盘上读取数据。
在读取字符串时,我先这样写
cout<<"请输入出版物标题:";
gets(title); //直接用了gets
cout<<"请输入价格:";
cin>>this->price;
结果报错
[Error] cannot convert ‘std::string {aka std::basic_string}’ to ‘char*’ for argument ‘1’ to ‘void str(char*)’
但是改用了
cin>>title;
或者
getline(cin,title);
就可以了。
用了某些大神说的把头改成
#include<iostream.h>
貌似不行。可能是编译器的原因。