打印

链表问题

[复制链接]
878|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
txcy|  楼主 | 2013-7-28 12:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
无冕之王| | 2013-7-28 12:45 | 只看该作者
重载 << 操作符
函数声明如下:
ostream& operator << (ostream& os, const student &object)
{
os << stu.id << endl;
os << stu.number << endl;
……  //把stu的成员都输出

return os;
}

然后
cout << *(LISTST.begin());

使用特权

评论回复
板凳
hsbjb| | 2013-7-28 13:02 | 只看该作者
你可以这样做:
在struct头文件中在结构体重增加一个operator<<()操作,再在同一文件中增加一个operator<<()调用类中的operator<<();

使用特权

评论回复
地板
秋天落叶| | 2013-7-28 13:11 | 只看该作者
struct student
{
  int id;
  int number;
  int score;
  char sex;
  string address;
  struct student *next;
}stu;

使用特权

评论回复
5
gxgclg| | 2013-7-28 19:13 | 只看该作者
2楼的方法应该可行

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

274

主题

2106

帖子

0

粉丝