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

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.

最佳答案

您没有清单。您有一个数组,其中包含51个要点列表的元素。
因此,要打印这些元素,您需要遍历数组并打印列表元素。
例如:

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;
        });
}

关于c++ - c++打印数组列表的元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19876467/

10-10 12:36