把报错复制到网上,还是不知道要怎么修改。

报错内容是这样的:error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)


#include<iostream>
#include<string>
using namespace std;
class employee
{
   public:
       employee(char n,char c,int co)
       {
           name=n;
           city=c;
           code=co;
       }
       void setValue()
       {
          
        cin>>name>>city>>code;
       }
       void display()
       {
        cout<<"name:"<<name<<"city:"<<city<<"code:"<<code<<endl;
       }
   private:
       char name;
       char city;
       int code;
};
      int main()
      {
          employee g1(0,0,0);
          employee g2(0,0,0);
          employee *p;
          g1.setValue();
          p=&g1;
          cout<<"the content of g1:"<<p->display()<<endl;
          g2.setValue();
          p=&g2;
          cout<<"the content of g2:"<<p->display()<<endl;
          return 0;
      }

修改好了后又出现运行错乱的问题,是为啥,一开始没有用双引号也是这样。
好像发不了图片,不知道为啥

cout<< p->display()
这里要输出display()的返回值,但是你的display返回值是void,因此报错。
可以分开写或者重载<<操作符。

p->display()返回的是void,不能用于cout。main里面改成这样:

int main()
{
    employee g1(0, 0, 0);
    employee g2(0, 0, 0);
    employee *p;
    g1.setValue();
    p = &g1;
    cout << "the content of g1:";
    p->display();
    cout << endl;//换行
    g2.setValue();
    p = &g2;
    cout << "the content of g2:";
    p->display();
    cout << endl;//换行
    return 0;
}