FILE * to istream??


I am using popen(3) in cstdio.

it returns a FILE * can I somehow
convert that to an istream or ifstream so I can
use iostream operations on the pipe?

(or is there a boost popen)
The Boost IOstreams library has a file_descriptor stream that can be created with boost::iostreams::file_descriptor(fileno(fp));
tried this, no luck.

1
2
3
    pipe = Popen("find . -type f", "r");
    istream in = boost::iostreams::file_descriptor(fileno(pipe));
 


god, the boost documentation is awful.
it's like trying to read an XML file.
what the hell is it talking about?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
#include <string>
#include <iostream>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>

namespace io = boost::iostreams;

int main()
{
    FILE* pipe = popen("find . -type f", "r");
    
    io::stream_buffer<io::file_descriptor_source> fpstream(fileno(pipe));
    std::istream in(&fpstream);
    
    std::string line;
    while (in)
    {
        std::getline(in, line);
        std::cout << line << std::endl;
    }
    return 0;
}


make LDFLAGS=-lboost_iostreams foo
Topic archived. No new replies allowed.