0

我有以下代码,我想打印数组中的每个元素。

struct pckt
{
    float gen_time;
    int node_id;
    bool last; 
    int seq;
    float end_time;
}

list<pckt> nodelist[51];

pckt newpckt;
newpckt.gen_time = inp;
newpckt.node_id = i;
newpckt.last = false;
newpckt.seq = 1;
newpckt.end_time = 1.0;

nodelist[i].push_back(newpckt);

// I wnat to print each element in array list. 
4

1 回答 1

3

你没有清单。您有一个包含 51 个要 pcks 的列表元素的数组。因此,要打印那些您需要遍历数组并打印列表元素的内容。
例如:

for(int i=0; i < 51; ++i)
{
    std::for_each(nodelist[i].begin(), nodelist[i].end(), 
        [](const pckt& e){
            std::cout << e.node_id << std::endl;
        });
}
于 2013-11-09T13:31:21.537 回答