Results 1 to 11 of 11

Thread: About buffers, iostream objects, and files.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About buffers, iostream objects, and files.

    I want to use iostream to read write data into memory, but I dont know how to .
    I lose myself with the way to create the io instance, asociate initial memory, etc.
    Basically I'd want to create a vector of io elements, on each vector I want to select the io object and then read - write data of any kind.

    I want to have the benefits of to use the 'write', put, seek, << , ><, etc.
    But the iostream ask me for a streambuf iostream (streambuf * sb);, and this element only let me to use filebuf and stringbuf :
    This is an abstract base class, therefore no objects can be directly instantiated from it. The standard hierarchy defines two classes derived from this one that can be used to directly instantiate objects: filebuf and stringbuf.

    So, my question is 'can I use this to work in memory' ? stringbuf is the way ?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: About buffers, iostream objects, and files.

    Quote Originally Posted by tonnot View Post
    I want to use iostream to read write data into memory, but I dont know how to .
    You are missing my point. You waste your time trying to use a stream in a non-streaming way. Choosing a particular approach over another has to be backed up by some evidence that there is a benefit of choosing this particular approach. You want to write binary data, you will not have any benefits from using streams. At least none that I see.

    Basically I'd want to create a vector of io elements, on each vector I want to select the io object and then read - write data of any kind.
    So far you are writing binary data, not "data of any kind".

    But the iostream ask me for a streambuf iostream (streambuf * sb);, and this element only let me to use filebuf and stringbuf :
    So subclass streambuf and create your own buffer type by implementing pure virtual methods.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About buffers, iostream objects, and files.

    Thanks wy.
    I have searched information about subclass streambuf. I dont find useful information.
    I fear to 'reinvent' the wheel.
    I dont understand why is so difficult to find a standard way to do what I want.
    Thanks again.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: About buffers, iostream objects, and files.

    Quote Originally Posted by tonnot View Post
    I dont understand why is so difficult to find a standard way to do what I want.
    Simply put, there isn't a standard way of reading/writing "data of any kind" (apart from the non-stream read/write methods). The standards only apply to data of known types. If you really want to handle "data of any kind" in a stream based manor, then you need to define your own methods for each kind of data, as already suggested.

Similar Threads

  1. The best way to use buffers / streams/ strstreams
    By tonnot in forum General Programming
    Replies: 0
    Last Post: 28th February 2011, 09:32
  2. About binary files & streams & buffers...
    By tonnot in forum General Programming
    Replies: 3
    Last Post: 22nd February 2011, 23:05
  3. #include<iostream> not found
    By byammanuru in forum Newbie
    Replies: 1
    Last Post: 20th November 2009, 09:39
  4. Print with iostream to console
    By afflictedd2 in forum Qt Programming
    Replies: 1
    Last Post: 17th March 2009, 17:03
  5. Iostream cout on loop same line
    By patrik08 in forum General Programming
    Replies: 3
    Last Post: 7th December 2006, 13:12

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
  •  
Qt is a trademark of The Qt Company.