error C2679

来源:互联网 发布:常用nosql数据库 编辑:程序博客网 时间:2024/05/21 13:27

问题:

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>

using namespace std;

class Student
{
int n;
string name;

public:
   void set( string str )
   {
    static int number = 0;
    name = str;
    n = ++number;
   }
  
   void print() { cout<<name<<" -> students are "<<n<<" numbers\n"; }
};

void fn()
{
Student s1;
s1.set("Jentt");
Student s2;
s2.set("Hank");
s1.print();
}

int main()
{
Student s;
s.set("Smith");
fn();
s.print();

return 0;
}

解决:程序开始加上

#include <string>

0 0