运行这段代码,每次输入都为2,结果color 后是空的?如果我改color为int型运行正确了,这是为什么?
#include
#include
using namespace std;
class ABC
{
private:
string label="0";
int rating=0;
protected:
string Label(){return label;}
int Rating(){return rating;}
public:
ABC(string la="null",int ra=-1):label(la),rating(ra){}
virtual void ViewABC()=0;
};
class lacksDMA:public ABC
{
private:
string color;
public:
lacksDMA(string co="null",string la="null",int ra=-1):ABC(la,ra),color(co){}
virtual void ViewABC()
{
cout<<"\n\nLabel:"<
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
问题在于你混用cin 和 getline。
如果你一定要混用的话,可以在cin之后加上