求怎么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;