Results 1 to 4 of 4

Thread: How to read/write sets of orderded numbers in binary

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to read/write sets of orderded numbers in binary

    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.
    Last edited by kaydknight; 9th March 2007 at 03:45.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.