我正在尝试制作一个简单的程序,将两个对象存储在链接列表中。当有人告诉我如何打印链接列表时,我有问题吗? 这是我的代码:
// Example program
#include <iostream>
#include <string>
#include <list>
using namespace std;
class Sales {
public:
int id;
int p_id;
int price;
};
int main()
{
list <Sales> sales;
Sales s1, s2;
s1.id = 1;
s1.p_id = 2;
s1.price = 400;
s2.id = 4;
s2.p_id = 3;
s2.price = 500;
sales.push_front(s1);
sales.push_front(s2);
int n = sales.size();
for (int i = 0; i<n; i++)
{
cout << sales.front();
}
}