Re: Help with stdiostream.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[I already sent a message to the mailing list but it got rejected 
 as spam. So, this is my second try and I thought I'd just include
 you in the To: list]
 
On Fri, Feb 20, 2004 at 06:36:24AM -0800, Kevin Stedman wrote:
> Is there an example someplace on how this is used.  I
> am getting errors trying to compile the code below on
> the line that uses the stdio_filebuf.
> 
> when i compile I get these error msgs:
> 
> 'lp_buf' undeclared
> 
> parse error before 'lp_pipe'

Obviously, you haven't read the comment in the header and you failed to
realize that stdio_filebuf is a template class.

Try this:

----------------------------------------------------------------------

#include <iostream>

#include <ext/stdio_filebuf.h>

#include <cstdio>
#include <unistd.h>

typedef __gnu_cxx::stdio_filebuf<char> stdiobuf;


using namespace std;

int main()
{
   FILE* p = popen ("cat", "w");
   
   if (p != NULL) 
     {
	stdiobuf p_buf (p, ios::out);
	
	ostream p_out (&p_buf);
	
	p_out << "foo\n" << "foo\n" << "bar\n" ;
	
	p_out.flush ();
	
	pclose (p);
     } else {
	cerr << "failed to open pipe." << endl;
     }
}

----------------------------------------------------------------------

HTH
-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux user                         - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux