kaydknight

9th March 2007, 03:40

Hello, I would like to ask a question.

Does anyone know how to effectively store a 2d array of numbers in binary file, and then able to read them later into array.

For example, This are the samples of numbers I need to write:

x1 x2 x3

y1 1 1 1

y2 2 2 3

y3 3 3 5

y4 4 5 6

y5 5 6 8

If in ascii, I can write like this:

1 1 1

2 2 2

3 3 5

...

5 6 8

But how about writing it into binary file?

When reading, How do I know when I reached end-of-row for one column and store next number on column+1 (since binary files are ordered sequentially).

I've been thinking of putting some kind of byte signal to indicate I reached end-of-row, but I don't have the idea how.

Also, I predict a problem, where later, my sets of number will be non-uniformed (1 col have 5 rows, next col have 9 rows and so on).

Can anyone give a simple example how to write it? I'm comfortable with using QDataStream and iostreams binary mode, but I think this is more a problem of the design of it.

E.g : After reading the binary file, I want to store them into array.

array[0,0] = 1

... and so on until

array[2,4] = 8

Thanks in advance! I've tried googling, but they only tell me the basics of binary read/write.

Does anyone know how to effectively store a 2d array of numbers in binary file, and then able to read them later into array.

For example, This are the samples of numbers I need to write:

x1 x2 x3

y1 1 1 1

y2 2 2 3

y3 3 3 5

y4 4 5 6

y5 5 6 8

If in ascii, I can write like this:

1 1 1

2 2 2

3 3 5

...

5 6 8

But how about writing it into binary file?

When reading, How do I know when I reached end-of-row for one column and store next number on column+1 (since binary files are ordered sequentially).

I've been thinking of putting some kind of byte signal to indicate I reached end-of-row, but I don't have the idea how.

Also, I predict a problem, where later, my sets of number will be non-uniformed (1 col have 5 rows, next col have 9 rows and so on).

Can anyone give a simple example how to write it? I'm comfortable with using QDataStream and iostreams binary mode, but I think this is more a problem of the design of it.

E.g : After reading the binary file, I want to store them into array.

array[0,0] = 1

... and so on until

array[2,4] = 8

Thanks in advance! I've tried googling, but they only tell me the basics of binary read/write.