gpt4 book ai didi

c++ - 从 txt 文件读取到 FIFO 队列中进行处理

转载 作者:行者123 更新时间:2023-11-30 02:20:31 32 4
gpt4 key购买 nike

我对如何使用队列以及如何实现它们感到困惑。我将不得不按顺序读取数据包,然后放入队列中进行处理。完成后,我将不得不从队列中顺序读取数据包,并根据它们的 VLAN 标记和优先级编号将它们重定向到两个优先级队列之一,这是文本文件中的示例,但大约有 10000 个他们。

55555555555555D507E34B68534300A0FF7538958100010000086461746162617365C704DD7B This is what the numbers mean

我遇到的问题是队列本身,我觉得我在做这一切时走错了路,我希望得到一些帮助。

https://pastebin.com/B4ZG2RmL <- 这是标题

using namespace std;

struct packetItem
{
string packet;
int packetInt;
};

int main()
{
packetItem newItem;
ifstream myfile("packets.txt");
int count = 0;
int vlan = 0, priority = 0;
const int v = 100;
char sArray[v];



const int size = 100;

if (myfile.is_open())
{
//while (myfile.good())
while (count < 10) // this 10 is here so it doesnt spam the output
{
myfile >> newItem.packet;
myfile.get(); //remove return
strcpy_s(sArray, newItem.packet.c_str());
int x = 0;

while (sArray[x] != '\0')
{
x++;
string part(sArray.substr(48, 4));
}
cout << count + 1 << ". " << sArray << "\n\t" <<x << "\n";
count++;
}
}
myfile.close();

system("pause");
return 0;
}

最佳答案

C++ 带有队列数据结构的标准实现。 Take a look !

这是一个使用您的数据包的简单示例:

std::queue<packetItem> pack_queue();
packetItem item;

while (/* What ever condition you choose */) {
stream >> item.packet;
pack_queue.push(item);

/* Process packet */
}

/* When you want to get the top packet, then just do this */
packetItem front_packet = pack_queue.front();

我知道这是一个非常简短的示例,因此请查看文档以更好地掌握。

我希望这能回答您的问题。它有点广泛。

关于c++ - 从 txt 文件读取到 FIFO 队列中进行处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49579036/

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