 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
va Guest
|
Posted: Mon May 07, 2007 11:25 pm Post subject: FILE *fd to string |
|
|
I have a C style function which is of the form writestuff(FILE *fd).
Now this function writes strings to the FILE* provided. Is there a way
to collect this output into a string (without the obvious creating and
reading of a temp file?). I just want the output of the 'writestuff'
function to be collected into a std::string. I can't modify the
writestuff function to do the needful. Any suggestions?
Thanks,
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Sebastian Redl Guest
|
Posted: Tue May 08, 2007 1:05 am Post subject: Re: FILE *fd to string |
|
|
On Mon, 7 May 2007, va wrote:
| Quote: | I have a C style function which is of the form writestuff(FILE *fd).
Now this function writes strings to the FILE* provided. Is there a way
to collect this output into a string (without the obvious creating and
reading of a temp file?). I just want the output of the 'writestuff'
function to be collected into a std::string. I can't modify the
writestuff function to do the needful. Any suggestions?
Thanks,
|
Not in a portable way, as FILE is opaque.
There are some non-portable ways.
For example, with knowledge of your CRT, you can construct a FILE
structure that writes into a memory buffer. (That's what the MS CRT does
for sprintf, for example.)
With knowledge of your platform, you can e.g. create a POSIX pipe and use
fdopen() to turn the write end of the pipe into a FILE*, then read the
strings from the other end.
But nothing portable, I'm afraid.
Sebastian Redl
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|