gpt4 book ai didi

C++打印数组列表的元素

转载 作者:行者123 更新时间:2023-11-28 00:38:45 25 4
gpt4 key购买 nike

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

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.

最佳答案

您没有列表。您有一个数组,其中包含 pcks 列表的 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++打印数组列表的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19876467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com