file descriptors, FILE* and std::fstream

I wanted to do proccess intercommunication.
Looked at pipe() and popen(), but as they being from C they work with file descriptors or FILE pointers.

The thing is, the syntax. I don't like the format string.
Also the classes have void print(ostream&); methods
¿Is there a way to convert them to std::fstream?

I guess that ostringstream could help, but it's a waste of memory.



The actual issue
$ ./intensive_computation | ./analyzer
But I want to see the output of the first, but that is not what the second should receive

Regards
Last edited on
1. Boost: boost::iostreams::file_descriptor_source and boost::iostreams::file_descriptor_sink
http://www.boost.org/doc/libs/1_49_0/libs/iostreams/doc/classes/file_descriptor.html

2. GNU: __gnu_cxx::stdio_filebuf<>
http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00069.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>
#include <ext/stdio_filebuf.h>

int main()
{
    std::FILE* c_stream = std::fopen( __FILE__, "r" ) ;
    {
        __gnu_cxx::stdio_filebuf<char> fbuf( c_stream, std::ios::in ) ;
        std::istream stm( &fbuf ) ;
        std::string line ;
        while( std::getline( stm, line ) ) std::cout << line << '\n' ;
    }
    std::fclose(c_stream) ;
}

Topic archived. No new replies allowed.