cpp 输出<< 重载

Posted on 2012-04-27 22:54  无忧consume  阅读(216)  评论(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

Copyright © 2024 无忧consume
Powered by .NET 8.0 on Kubernetes