语法:operator<<;
作用:可以输出自定义
#include <iostream> #include <string> using namespace std; class person { friend ostream& operator<<(ostream &cout, person &p); public: person(int a,int b) { m_A = a; m_B = b; } private: int m_A; int m_B; }; ostream& operator<<(ostream &cout,person &p) //相当于cout << p; { cout << "p.m_A=" << p.m_A << "p.m_b=" << p.m_B << endl; return cout; } int main() { person p1(10,10); cout << p1 << endl; system("pause"); return 0; }