M
marco
===================================================
I've posted the same message to comp.lang.c++.moderated
===================================================
hi everybody
I've written a small program posted below in the message.
It should print the content of a generic file in a shell window by a
pipe.
I use a popen() function to create a pipe and stdio_filebuf to
interface it
with a ostrem object.
I compile the program with g++ 3.2.3 and I don't have any problem
about the compilation.
When I try to execute the program I receive a "segmentation fault".
The program works properly if I put the code relative to popen
function and the
stdio_filebuf object in the main. I don't understand which is the
problem.
Any idea?
Thanks
Marco
=======================================================
Code
#include <ext/stdio_filebuf.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
typedef __gnu_cxx::stdio_filebuf<char> filebuf_gnu;
filebuf_gnu& open(char *command)
{
f=popen(command,"w");
filebuf_gnu tempw(f,std::ios_base:ut,1024);
filebuf_gnu &pnt=tempw;
return (pnt);
}
int main()
{
filebuf_gnu &temp = (open("cat"));
std:stream out(&temp);
std::ifstream file("../src/prova_marco.cxx");
if (!file) cout<<"errore apertura file";
out<<file.rdbuf();
return 0;
}
=============================================================
I've posted the same message to comp.lang.c++.moderated
===================================================
hi everybody
I've written a small program posted below in the message.
It should print the content of a generic file in a shell window by a
pipe.
I use a popen() function to create a pipe and stdio_filebuf to
interface it
with a ostrem object.
I compile the program with g++ 3.2.3 and I don't have any problem
about the compilation.
When I try to execute the program I receive a "segmentation fault".
The program works properly if I put the code relative to popen
function and the
stdio_filebuf object in the main. I don't understand which is the
problem.
Any idea?
Thanks
Marco
=======================================================
Code
#include <ext/stdio_filebuf.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
typedef __gnu_cxx::stdio_filebuf<char> filebuf_gnu;
filebuf_gnu& open(char *command)
{
f=popen(command,"w");
filebuf_gnu tempw(f,std::ios_base:ut,1024);
filebuf_gnu &pnt=tempw;
return (pnt);
}
int main()
{
filebuf_gnu &temp = (open("cat"));
std:stream out(&temp);
std::ifstream file("../src/prova_marco.cxx");
if (!file) cout<<"errore apertura file";
out<<file.rdbuf();
return 0;
}
=============================================================