Image

Imageopenreel wrote in Imagecpp 2D after a push & pull feeling

Using read(), write() with 2D dynamic arrays?

It took me a while (being self-learned and sort of learning things as I need to rather than in any orderly, disciplined way) to realize how easy it is to use the read() and write() functions in fstream, especially for "dumping" the entire contents of an array to a file in one line.

My first question is, does this still work when the array is allocated dynamically with new? I would assume yes ...

But then, suppose I'm allocating a 2-or-more-D array; first by allocating an array of pointers and then using a for loop to allocate each row (or column actually). Is it possible to use a single write() to dump the entire 2D array, using width*height*sizeof(type) as the second argument, or would I have use a for loop?