我想创建一个可以在单个单元格中存储 ID 和内容的数组。我想存储这些信息,以便我可以从一个输入中接收到两条信息。
目前我是这样做的:
int order[100];
int content[100];
int count = 0;
//method for adding a new piece of information
void setFrame(int nextOrder, int nextContent){
order[count] = nextOrder;
content[count] = nextContent;
count++;
}
这可行,但我想要一种方法来调用单个数组,例如 Array[i],并从中获取两个整数。我怎样才能做到这一点?
最佳答案
您可以使用标准类 std::pair
在 header 中声明 <utility>
#include <utility>
//...
std::pair<int, int> order[100];
void setFrame( int nextOrder, int nextContent )
{
order[count++] = { nextOrder, nextContent };
}
关于c++ - 如何在一个数组中存储两个整数 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29110099/