11_19.cpp

来自「c++案例教程源代码」· C++ 代码 · 共 20 行

CPP
20
字号
#include <iostream>
#include <iomanip>
using namespace std;
class NoParam    
{int  integer;
public :
	NoParam(int x  = 0)    {integer= x;}
	friend  ostream&  operator <<(ostream&, NoParam&);
	friend  istream&  operator >>(istream&, NoParam&);
};
istream&  operator >> (istream &is, NoParam &np){	return is  >>np.integer;}
ostream&  operator << (ostream &os, NoParam &np){	return os << np.integer;}
ostream&  arrow(ostream &os)	{	return os  <<"-->";}	//定义无参操作操纵符
int main ()
{	NoParam np(5);
	cout << "The object is:"<<np <<endl;
	cout << "Object np" << arrow << np << endl;			//使用无参操纵符
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?