首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求如何C++写一个结构体链表

2013-08-14 
求怎么C++写一个结构体链表要求写一个结构体链表,比如一个liststudent LISTSTstruct student{int idint

求怎么C++写一个结构体链表
要求写一个结构体链表,比如一个list<student> LISTST
struct student
{
  int id;
  int number;
  int score; 
  char sex;
  string address;
}stu;
怎么用C++写出一个个输出里面的元素啊,我不明白该把list做对象还是把struct做对象。求大神帮我写下看看
[解决办法]
1. 重载operator <<(std::ostream&)

2. BOOST_FUSION_ADAPT_STRUCT
[解决办法]
重载 << 操作符
函数声明如下:
ostream& operator << (ostream& os, const student &object)
{
os << stu.id << endl;
os << stu.number << endl;
……  //把stu的成员都输出

return os;
}

然后
cout << *(LISTST.begin());
[解决办法]

struct student
{
  int id;
  int number;
  int score; 
  char sex;
  string address;
  struct student *next;
}stu;

热点排行