Results 1 to 4 of 4

Thread: writing in to a string via FILE*

  1. #1
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question writing in to a string via FILE*

    I have some (C-)code that wants a FILE*.
    In this file (pointer) the output I want is written.

    I don't want to create files (if I don't have to). I am merely interested in the output produced.

    Is it possible to somehow create a FILE* that prints (directly) into some buffer?
    (A C equivalent of std:stringstream, so to speak.)

    Obviously I can create a temporary file, pass that to the function, read the contents of the file and the delete it... (which is what I am doing right now). I was just wondering if there was a more elegant (and succinct, faster due to no file IO etc.) way to achieve that.

    Thanks
    Christoph

  2. #2

    Default Re: writing in to a string via FILE*

    Creating temporary file might made all process very slow.
    HostV - VPS Hosting - http://www.hostv.com

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

    Default Re: writing in to a string via FILE*

    There is a function to convert a file descriptor into a FILE pointer, but I don't think you'll find a way to map it to a string. Doing it the other way is easy using mmap but a reverse operation is probably not available.

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: writing in to a string via FILE*

    thank you.
    I'll post here if I should stumble upon a better solution.

Similar Threads

  1. Writing System in QFontDialog?
    By ashukla in forum Qt Programming
    Replies: 12
    Last Post: 23rd January 2008, 10:17
  2. Replies: 5
    Last Post: 10th January 2008, 13:26
  3. Reading from sockets in a multithreaded program
    By KoosKoets in forum Qt Programming
    Replies: 9
    Last Post: 4th April 2007, 20:43
  4. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  5. Create pixmap image from string
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2006, 16:38

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.