初学C++遇到苦难QAQ
#include<stdlib.h>#include<iostream.h>#include<string>usingnamespacestd;classCat{priv...
#include <stdlib.h>
#include <iostream.h>
#include <string>
using namespace std;
class Cat
{
private:
string name;
string color;
public:
void yell()
{ cout<<"喵喵"<<endl;}
void setName(string _name)
{ name=_name; }
string getName()
{return name;}
void setColor(string _color)
{ color=_color;}
string getColor()
{return color;}
};
int main(void)
{
Cat cat;
cat.setColor("yellow");
cat.setName("merry");
cat.yell();
cout << cat.getColor() << " " << cat.getName() << endl;
system("pause");
return 0;
}
错误为
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion) 展开
#include <iostream.h>
#include <string>
using namespace std;
class Cat
{
private:
string name;
string color;
public:
void yell()
{ cout<<"喵喵"<<endl;}
void setName(string _name)
{ name=_name; }
string getName()
{return name;}
void setColor(string _color)
{ color=_color;}
string getColor()
{return color;}
};
int main(void)
{
Cat cat;
cat.setColor("yellow");
cat.setName("merry");
cat.yell();
cout << cat.getColor() << " " << cat.getName() << endl;
system("pause");
return 0;
}
错误为
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询