gpt4 book ai didi

c++ - 错误 : assignment to '_List_iterator' from 'int'

转载 作者:行者123 更新时间:2023-11-30 05:33:59 28 4
gpt4 key购买 nike

我正在尝试实现一个将存储相关索引的列表。但是,我在标题中提到的 for (index_itr = (list_size - numberOfEvents - 1) 处遇到错误。我在做什么错误,以及如何更正它?

void logPrintEntry(UINT32 index, UINT32 portID, UINT16 numberOfEvents)
{
LOG_ENTRY log;
list <UINT32> list_telnet_indices;
log = (pLOG_ENTRY) &(Data.Log.log[index]);
list <UINT32> ::iterator index_itr;
UINT16 list_size = list_telnet_indices.size();
if( list_size <= numberOfEvents )
{
// print all logs
for ( index_itr = list_telnet_indices.begin();
index_itr != list_telnet_indices.end(); ++index_itr )
{
printDataOnly(log, *index_itr, portID);
}
}
else
{
// print only the last relevant entries
for (index_itr = (list_size - numberOfEvents - 1); //error: assignment to '_List_iterator<unsigned int,unsigned int &,unsigned int *>' from 'int'
index_itr != list_telnet_indices.end(); ++index_itr)
{
printDataOnly(log, *index_itr, portID);
}
}
}

最佳答案

index_itr 是一个迭代器,list_size - numberOfEvents - 1 是一个整数。这些不兼容。

使用std::advance设置 std::list

的迭代器
#include <iterator>     // std::advance

index_itr = list_telnet_indices.begin();
std::advance(index_itr, list_size - numberOfEvents - 1);
for (; index_itr != list_telnet_indices.end(); ++index_itr)
{
...
}

关于c++ - 错误 : assignment to '_List_iterator<unsigned int,unsigned int &,unsigned int *>' from 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34495690/

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