ostream重载问题
#include<iostream>#include <stdlib.h>using namespace std;class three_d{private: int x,y,z;public: three_d(int a,int b,int c):x(a),y(b),z(c) {} friend ostream & operator <<(ostream &s,three_d &obj);};ostream & operator <<(ostream &s,three_d &obj){ s<<obj.x<<","; s<<obj.y<<","; s<<obj.z<<","; return s;}int main(){ three_d a(1,2,3),b(3,4,5),c(6,7,8); cout<<a; system("pause"); return 0;}#include<iostream>#include <stdlib.h>using namespace std;class three_d{private: int x,y,z;public: three_d(int a,int b,int c):x(a),y(b),z(c) {} friend ostream & operator <<(ostream &s,three_d &obj) { s<<obj.x<<","; s<<obj.y<<","; s<<obj.z<<","; return s; }};int main(){ three_d a(1,2,3),b(3,4,5),c(6,7,8); cout<<a; system("pause"); return 0;}