#ifndef STUDENT_H #define STUDENT_H #include#include //#include using namespace std; class Student { public: Student(string name = "",int age = 0); friend ostream &operator<< (const Student &v,ostream &out) { out << "姓名" << v.m_name << "t年龄" << v.m_age ; return out; } string m_name; int m_age; }; #endif // STUDENT_H
应改为: friend ostream &operator<< (ostream &out,const Student &v)
容器:
vectorv; v.push_back(Student("xix",18)); v.push_back(Student("luc",13)); v.push_back(Student("alice",15)); for(int i = 0;i < v.size();i++) { //cout << "姓名" << v[i].m_name << "t年龄" << v[i].m_age << endl; cout << v[i] << endl; }


![[C++笔记]左移运算符重载错误分析 [Error]no match for ‘operator<<‘无匹配的左移运算符 [C++笔记]左移运算符重载错误分析 [Error]no match for ‘operator<<‘无匹配的左移运算符](http://www.mshxw.com/aiimages/31/1028000.png)
