I want to read the pixel values from a pgm file, then compute the integral image and save the result to a text file. At first I used Dev C++ to compile my code, but the pixel values have segmentation faults(Only the first three rows are correct). My instructor said there were two small bugs in my code which caused segmentation faults, but I don't know where the bugs are. She also said that she cannot compile my code on visual studio, she wants me to send her a C++11 compliant version, what does that mean?
Dynamic arrays are fine, and you handle them correctly.
Segmentation faults are caused by trying to access memory outside of array bounds. You do that on lines 43 and 46. integral[...][0-1] == integral[...][-1] == segmentation fault. Fix it by considering what value i starts with on lines 42 and 45.
You have two other major errors that will confuse you:
1) You are obtaining the pixel value as a char. However, the value of the character '0', for example, is not zero. You should be inputting the values as ints!
2) You don't need that streamstream. Get rid of it and just read directly from your infile.
Thanks for the reply. I have revised lines 43 and 46 and the dynamic arrays in the above code, now it can read the header correctly, showing the right version, comment, and size. But the pixel values of the pgm file were still wrong. Only the first two rows were correct.
*I used matlab to read the pgm file before, the pixel values read by matlab don't match with the pixel values read by visual c++ (only the first two rows are the same), is it possible that the pixel values would be different when using different software?
Assuming you also read the rest of my answer and fixed the pixel color input, then I do not know why you would get only two lines correctly and the rest as garbage.