//--《C++捷径教程》读书笔记--Chapter 18--C++的I/O系统
//--Chapter 18--C++的I/O系统
//--10/15/2006 Sun.
//--Computer Lab
//--Liwei
//说明插入符的用法
#include <iostream>
using namespace std;
class three_d{
public:
int x,y,z;
three_d(int a, int b, int c){ x=a; y=b; z=c; }
};
ostream &operator<<( ostream &stream, three_d obj )
{
stream << obj.x << ",";
stream << obj.y << ",";
stream << obj.z << "/n";
return stream;
}
int main()
{
three_d a(1,2,3), b(4,5,6), c(7,8,9);
cout << a << b << c;
return 0;
}
本文介绍C++中自定义类的输出操作符重载方法,通过一个三维坐标类的例子展示了如何实现<<操作符的重载以方便进行对象数据的输出。

被折叠的 条评论
为什么被折叠?



