cpp 输出<< 重载

Posted on 2012-04-27 22:54  无忧consume  阅读(220)  评论(0)    收藏  举报

#include <iostream>

using namespace std;

struct vertex{
int x;
int y;
int z;
// Input and Output
friend std::ostream& operator<<(std::ostream& os, const vertex& vo);

};
std::ostream&operator<<(std::ostream& os, const vertex& vo)
{
return os << "<" << vo.x << ", " << vo.y << ", " << vo.z << ">";
}

void main()
{
vertex v;
v.x = 0;
v.y = 1;
v.z = 2;
cout<<v;
return;
}

//输出<0, 1, 2>Press any key to continue

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3