问题:
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>