c++ - 从二维数组中检索数组元素

标签 c++

我想在二维数组中存储 256*256 个条目。我这样做:

struct Data
{
    int Serial_Number;
    int NextIndex;
} ;

struct Data Index[256][256];


Data obj1;
obj1.Serial_Number=1;
obj1.NextIndex=5;

Index[3][240]=obj1;

现在,一旦我存储了所有这些值,我将如何从数组元素中检索每个值?

比如我想检索存储在 Index[3][240] 中的值。

其次,这种方法是否比 unordered_map 更快?

最佳答案

struct Data
{
    int Serial_Number;
    int NextIndex;
} ;

struct Data Index[256][256]; //should be this

Data obj1;
obj1.Serial_Number=1;
obj1.NextIndex=5;

Index[3][240]=obj1;

检索数据: struct Data data = Index[3][240];

访问一个结构的数据: data.Serial_Number;

关于c++ - 从二维数组中检索数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22601766/

相关文章:

c++ - ifstream 通过引用返回对象

c++ - 将模板(没有规范)传递给 std::thread() 会出现错误:<未解析的重载函数类型>匹配错误

C++ MFC : Draw a bitmap into a CFrame

c++ - 添加和删​​除最后一位

c++ - 如何对包含 const 值的 vector 进行排序

c++ - 添加该行的所有总和

c++ - 如何使用 boost::mpl 编写策略?

c++ - 将 boost::any 转换为 boost::variant 的通用函数

c++ - goto 和 junping 循环循环 c++

c++ - C/C++ GetAsyncKeyState() 组合键