regards,
Lucas
[EMAIL PROTECTED] wrote:
On Thu, Mar 11, 2004 at 01:10:16AM +1100, Matthew Wlazlo wrote:
Ok let's try that again (hope i read the question right this time!)
using namespace std; using namespace __gnu_cxx;
....
int fd = open("test.txt", O_RDONLY); stdio_filebuf<char> in(fd, ios::in, false, 1024); istream inf(&in);
string str; while(!inf.eof()) { inf >> str; cout << str << endl; }
close(fd);
Thanks! I modified that program to use popen, added the required headers, did a bit of error checking and stuff and got the following. Tested under solaris/gcc3.3.1 and fedora/gcc3.3.2:
Note that I needed to change your if (!feof...). because I was getting "world" twice. I guess that was a bug. Anyway while(inf << ...) is more idiomatic imho. I got the same bug with fopen as well as popen, fwiw.
#include <iostream> #include <cstdio> #include <ext/stdio_filebuf.h>
using namespace std; using namespace __gnu_cxx;
int main() {
FILE* fp = popen("echo hello, world", "r"); if (0 == fp) { perror("popen"); return 1; }
stdio_filebuf<char> in(fp, ios::in); istream inf(&in);
string str; while(inf >> str) { cout << str << endl; } cout << flush;
if (-1 == fclose(fp)) { perror("fclose"); return 1; } }
************************************************************************
The information contained in this e-mail message and any accompanying files
is or may be confidential.If you are not the intended recipient, any use, dissemination, reliance,forwarding, printing or copying of this e-mail or
any attached files is unauthorised.This e-mail is subject to copyright. No
part of it should be reproduced,adapted or communicated without the written
consent of the copyright owner.If you have received this e-mail in error,
please advise the sender immediately by return e-mail, or telephone and
delete all copies.Fairfax does not guarantee the accuracy or completeness
of any information contained in this e-mail or attached files. Internet
communications are not secure, therefore Fairfax does not accept legal
responsibility for the contents of this message or attached files.
************************************************************************
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html