如何在c++中对多维数组使用for each循环



好的,首先你应该注意到我使用的是visual studio 2010。无论如何,我得到一个非常奇怪的错误在我的每个循环,没有任何意义的我。

BYTE CPUKeys[][0x10] =
{
    {0x28,0x53,0x71,0xD9,0x7B,0x47,0xCC,0x50,0xAF,0x45,0x8D,0xB3,0xED,0x53,0x22,0x13},//Randy//encrypted
    {0x6E,0x38,0xB0,0xEF,0x6E,0x96,0x20,0x16,0xE5,0xCA,0x4B,0xE9,0x23,0x4E,0xC6,0xA5},//Josh//encrypted
    {0x95,0x2C,0x20,0x98,0xF9,0x99,0x28,0x0F,0xEE,0xA7,0x8F,0x48,0x58,0x01,0xB7,0x07},//Falcon//encrypted
    {0x64,0xDC,0x1E,0xFA,0xD2,0xAE,0x57,0x6C,0x0B,0xD0,0x39,0x6A,0x13,0x2C,0x91,0xE0},//Justin//encrypted
    {0x8D,0x82,0x6D,0x71,0x82,0xDC,0x83,0x8F,0x79,0x51,0xB8,0x7C,0x1F,0xC1,0xBF,0xD4},//Bypass//encrypted
    {0x27,0xF2,0xA7,0xF3,0xE2,0xDC,0x01,0x19,0x17,0xF4,0x11,0xFE,0xE9,0xB5,0x0C,0x2C},//Surge//encrypted
    {0x6D,0x7C,0x86,0x9A,0x6A,0xE1,0xD4,0x10,0x76,0x16,0x11,0x7C,0xED,0xB3,0x4D,0x56},//Noel//encrypted
    {0x3D,0x6C,0x88,0x8C,0x9D,0x3A,0xA5,0x40,0x64,0xDF,0xDF,0x8D,0x94,0xFD,0x28,0xF1},//XexRgh//encrypted
    {0x06,0x0D,0x8C,0xB6,0xB6,0x6D,0x29,0xD7,0x41,0xE1,0x13,0x35,0x84,0x80,0x68,0x31}//Zoobzy//encrypted
};

好了,这就是我的多维字节数组

for each(BYTE ID[0x10] in CPUKeys)
{

每个循环都有my for。发生的奇怪的事情是我的错误,我得到了ID。错误提示:"for each"迭代器类型"BYTE[16]"与元素类型"BYTE[16]"不兼容。知道它为什么会这么说吗?我做错了什么?我该如何改正?

如果可以的话试试:

for(auto& rows: CPUKeys)// Iterating over rows
{
    for(auto& elem: rows)
    {
        // iterate every row's column
    }
}

据我所知,c++中没有每个循环。用两个for循环代替。像这样

for (int i = 0; i < 9; ++i)
{
   for (int j = 0; j < 16; ++j)
   {
     BYTE value = CPUKeys[i][j];
   }
}

相关内容

  • 没有找到相关文章

最新更新