所以我的老師給了我這塊代碼來實現,基本上這裏的總體目標是在將PPM圖像寫入文件之後製作棋盤圖案。將所有文件寫入文件對我來說都是非常明顯的,問題是我得到的所有數據都是我的數組中的零。我怎樣才能實現這段代碼?
大塊我的導師給了我。
int col = ((w & 0x08) == 0)^((h & 0x08) == 0);
raster[i][j].r = static_cast<float>(col);
raster[i][j].g = static_cast<float>(col & 0x00);
raster[i][j].b = static_cast<float>(col & 0x11);
這是我的。
#include <iostream>
using namespace std;
struct RGB{
float r;
float g;
float b;
};
int main(){
//Declare Variables
int h;
int w;
//User Feedback
cout << "Please input height then width" << endl;
cin >> h >> w;
RGB raster[h][w];
//Assignment loop i = h and j = w
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
int col = ((w & 0x08) == 0)^((h & 0x08) == 0);
raster[i][j].r = static_cast<float>(col);
raster[i][j].g = static_cast<float>(col & 0x00);
raster[i][j].b = static_cast<float>(col & 0x11);
cout << raster[i][j].b << endl;
}
}
return 0;
}
如果有人可以解釋我在做什麼錯我會非常感激。我一直被困在這個問題上,並且迄今爲止嘗試了很多不同的東西。
我發現了這個問題。我的迭代器具有非常高的價值,它確實是隨機的。任何人有任何想法爲什麼?
你有調試嗎?你學到了什麼? – Carcigenicate
不幸的是我知道我的IDE非常糟糕,它在調試時崩潰,我不得不重新啓動。 – Tykota
您是否嘗試用調試器逐步執行代碼?另外,_standard_ C++不支持VLAs('RGB raster [h] [w];')。 –