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

[C++] popen and ofstream(int) with g++ 3.0



Hi!

I have some trouble with tela.  When compiling with g++ 3.0, there is
no ofstream(int) function (as in STL).  This gives a problem when
using popen(), as it returns a FILE*, and tela then uses an ofstream
to read from the process.  I've used the patch below, but I'd say it's
an ugly hack.  What's the suggested way to use popen functionality
with STL?

/Micce

--- tela--buildsystem--1.0--patch-7/std.ct	Sun Feb 24 02:50:38 2002
+++ tela--buildsystem--1.0--patch-8/std.ct	Sun Feb 24 02:51:32 2002
@@ -4091,8 +4091,10 @@
 	FILE *fp = popen(s,"w");
 	if (!fp) return -1;
 	cout << flush;
-	ofstream out;
-	out.attach(fileno(fp));
+	char * dumname= (char*)malloc(12);
+	sprintf(dumname,"/dev/fd/%i", fileno(fp));
+	ofstream out(dumname);
+	free(dumname);
 	for (THashEntryPtr p=theHT.first(); p; p=theHT.next()) {TObjectPtr objptr = p->value();
 		if (objptr) {
 			Tkind k = objptr->kind();




-- 
Mikael Hedin, MSc                   +46 (0)980 79176
Swedish Institute of Space Physics  +46 (0)8 344979 (home)
Box 812, S-981 28 KIRUNA, Sweden    +46 (0)70 5891533 (mobile)
[gpg key fingerprint = 387F A8DB DC2A 50E3 FE26  30C4 5793 29D3 C01B 2A22]



Reply to: