看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) NO 問題(Question): 當我在使用指標寫入資料時,出現了嘗試讀取或寫入受保護的記憶體。 這通常表示其他記憶體已損毀。這個Exception 餵入的資料(Input): NO 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) Bitmap^ openImg; openImg=gcnew Bitmap(pictureBox1->Image); Bitmap^ temp=gcnew Bitmap(openImg ->Width,openImg->Height); String^ M=textBox4->Text; int m, r, y, tem=0; int *cub; if(String::IsNullOrEmpty(M)) m=0; else m=System::Convert::ToInt32(M); int masksize=m*m; int u=m/2; if(m%2 != 0){ for(int i=u;i<temp->Height-u;i++){ for(int j=u;j<temp->Width-u;j++){ cub=new int[masksize]; r=0; y=0; for(int z=0;z<m^2;z++){ Color RGB=openImg->GetPixel(j-u+r,i-u+y); *(cub+z)=RGB.B; //出錯於這行 r++; if(r == m){ r=0; y++; } } for(int k=0;k<m;k++){ for(int q=0;q<8;q++){ if(*(cub+q) > *(cub+(q+1))){ tem=*(cub+(q+1)); *(cub+(q+1))=*(cub+q); *(cub+q)=tem; } } } int sommedian=*(cub+(m^2/2)); delete [] cub; temp->SetPixel(j,i,Color::FromArgb(sommedian,sommedian,sommedian)); } pictureBox2->Image=temp; } } 補充說明(Supplement): 請問這是哪裡出錯? 需要怎麼解決 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.234.231 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1490339377.A.4F1.html
achicn3: 誒可以用m^2哦? 好奇一問 03/24 15:40
uranusjr: ^ 是 XOR 運算子啊 03/24 15:41
steve1012: 不format一下真的很難讀啊 03/24 15:45
steve1012: 何不print z看看你有沒有超界? 感覺就是超界了 03/24 15:47
steve1012: 話說你indent也太多層了 不考慮多寫一個function嗎XD 03/24 15:48
steve1012: 然後自己寫一個swap function 03/24 15:49
achicn3: 對吼感謝解釋 我以為他是要m*m...沒看太仔細 03/24 15:58
LPH66: 呃, 我看下來的感覺原 PO 似乎就是要 m*m... 03/24 16:48
LPH66: 這種地方 m^2 的結果應該沒什麼用 03/24 16:48
steve1012: XD 03/24 23:32
a34021501: 不同版本的Win10可能有不同結果! 03/25 03:56
Bencrie: 樓上你不要來害人 03/25 22:30