By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

can you make an ifstream from a FILE* ?

P: n/a
Hi All,

In trying to learn streams I'd like to rewrite this from the popen man
page:

#include <stdio.h>
#include <stdlib.h>
main( )
{
char *cmd = "/usr/bin/ls *.c";
char buf[BUFSIZ];
FILE *ptr;

if ((ptr = popen(cmd, "r")) != NULL)
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);
(void) pclose(ptr);
return 0;
}
I was going to try to use istream_iterator and std::copy. Is it
possible to get the FILE* into an ifstream object?

Thanks much for my stupid question. Sincerely, G

Dec 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

George wrote in message
<11**********************@o13g2000cwo.googlegroups .com>...
Hi All,

In trying to learn streams I'd like to rewrite this from the popen man
page:


<an uneducated suggestion>
Look in the iostream docs:

"Reading/writing from/to a pipe"

The procbuf class is a GNU extension. It is derived from streambuf. A procbuf
can be closed (in which case it does nothing), or open (in which case it
allows communicating through a pipe with some other program).

Constructor: procbuf::procbuf (const char *command, int mode)
Calls `procbuf::open (command, mode)'.

--
Bob R
POVrookie
Dec 15 '05 #2

P: n/a
On 2005-12-15, George <ge**********@excite.com> wrote:
Hi All,

In trying to learn streams I'd like to rewrite this from the popen man
page:

#include <stdio.h>
#include <stdlib.h>
main( )
{
char *cmd = "/usr/bin/ls *.c";
char buf[BUFSIZ];
FILE *ptr;

if ((ptr = popen(cmd, "r")) != NULL)
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);
(void) pclose(ptr);
return 0;
}
I was going to try to use istream_iterator and std::copy. Is
it possible to get the FILE* into an ifstream object?


A quick perusal of my docs and the draft standard suggests it is
not possible with a standard function.

--
Neil Cerutti
Dec 15 '05 #3

P: n/a
Awesome, thanks much all for the tips

Dec 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.