本文介绍了多维数组的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在将一些C#代码移植到C ++,但有一点让我有些困惑.代码如下:
Hello all,
I am porting some C# code to C++ and there is a particular bit that has me a bit perplexed. The code is as follows:
byte [,,] data = new byte[d,h,w];
int i=0;
for (int z = 0; z < d; z++)
{
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
data[z,y,x]=bytes[i++];
}
}
}
因此,变量bytes
包含我从文件中读取的数据.通常,我将按以下方式计算线性指数:
So, the variable bytes
contains data that I have read from the file. Normally, I would calculate the linear index as follows:
index = (z*h+y)*w+x;
但是,在这种情况下,这似乎不是正确的选择.我想知道是否有人知道我做错了什么明显的事情...
谢谢,
Keith
However, this seems to be not be the right thing in this case. I was wondering if someone knows if I am doing something obviously wrong...
Thanks,
Keith
推荐答案
这篇关于多维数组的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!