c++运算符重载——左移运算符

语法: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;
}

上一篇:Kubernetes进程 Namespace 技术 Cgroups 技术


下一篇:C++学习笔记(2):选择结构、循环结构、跳转语句