正确初始化多维向量

时间:2016-01-11 19:01:18

标签: c++ boost vector

假设在C中有以下代码:

const unsigned char C[12][64] = {
        {
            0xB1, 0x08, 0x5B, 0xDA, 0x1E, 0xCA, 0xDA, 0xE9, 0xEB, 0xCB, 0x2F, 0x81, 0xC0, 0x65, 0x7C, 0x1F,
            0x2F, 0x6A, 0x76, 0x43, 0x2E, 0x45, 0xD0, 0x16, 0x71, 0x4E, 0xB8, 0x8D, 0x75, 0x85, 0xC4, 0xFC,
            0x4B, 0x7C, 0xE0, 0x91, 0x92, 0x67, 0x69, 0x01, 0xA2, 0x42, 0x2A, 0x08, 0xA4, 0x60, 0xD3, 0x15,
            0x05, 0x76, 0x74, 0x36, 0xCC, 0x74, 0x4D, 0x23, 0xDD, 0x80, 0x65, 0x59, 0xF2, 0xA6, 0x45, 0x07
        },
        {
            0x6F, 0xA3, 0xB5, 0x8A, 0xA9, 0x9D, 0x2F, 0x1A, 0x4F, 0xE3, 0x9D, 0x46, 0x0F, 0x70, 0xB5, 0xD7,
            0xF3, 0xFE, 0xEA, 0x72, 0x0A, 0x23, 0x2B, 0x98, 0x61, 0xD5, 0x5E, 0x0F, 0x16, 0xB5, 0x01, 0x31,
            0x9A, 0xB5, 0x17, 0x6B, 0x12, 0xD6, 0x99, 0x58, 0x5C, 0xB5, 0x61, 0xC2, 0xDB, 0x0A, 0xA7, 0xCA,
            0x55, 0xDD, 0xA2, 0x1B, 0xD7, 0xCB, 0xCD, 0x56, 0xE6, 0x79, 0x04, 0x70, 0x21, 0xB1, 0x9B, 0xB7
        },

and so on

如何将其转换为std::vector以便向量初始化所有必要的值?

在矢量下我假设vector< vector<uint8_t> >

或者我最好使用boost::multi_array

1 个答案:

答案 0 :(得分:2)

从C ++ 11开始,您可以使用初始化列表初始化向量。你可以简单地改变

const unsigned char C[12][64] = ...

std::vector<std::vector<unsigned char>> C = ...

Live Example