简体   繁体   English

数组/向量C ++推送?

[英]Arrays / vectors c++ pushing?

I need to create a keyed array that I can push data to. 我需要创建一个可以将数据推送到的键控数组。

I need to store id and time, and on an event push a new id and time to the array. 我需要存储ID和时间,并在事件上将新的ID和时间推入数组。

After a look around, many people have suggested vectors. 环顾四周后,许多人建议使用矢量。

I'm not sure how I would implement it though, having two keys, and how to push to them? 我不确定我将如何实现它,有两个键,以及如何按下它们?

If anyone could help? 如果有人可以帮忙?

Use a std::vector of std::pair<T,U> , where T and U are suitable data types for the id and the time. 使用std::pair<T,U>std::vector ,其中TU是ID和时间的合适数据类型。

For example: 例如:

std::vector<std::pair<int, long> > v;
v.push_back(std::make_pair(1, 2L));
v.push_back(std::make_pair(1, 2L));
v.push_back(std::make_pair(2, 2L));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM