Topic: strstream


Author: anneke@faculty.chem.ruu.nl (Anneke)
Date: Mon, 6 Mar 1995 16:14:44 GMT
Raw View
Please help, I am desperately trying to get this work.

Why does this compile and execute ok ....

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

#include <strstream.h>

ostream &Output(char *s)
{
   return cerr << s;
}


main()
{
   int i=8;

   Output("value: ") << i << endl;
}


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

.... while this gives a compiler error with gcc 2.6.2 ...

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

#include <strstream.h>
#include <stdio.h> // for temporary puts

void Output(ostrstream &os)
{
   puts(os.str()); // to be replaced by custom popup message window call
}

ostrstream & Format(char *s)
{
   static char bf[256];
   static ostrstream ostr(bf,255);
   ostr << s;
   return ostr;
}


main()
{
   int i=8;

   Output(Format("value") << i << ends);
}

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

str.C: In function `int main()':
str.C:42: cannot convert type `ostream' to type `ostrstream &'
str.C:25: in passing argument 1 of `Output(ostrstream &)'

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

I want to have the flexibility of stream io instead of format strings
to be able to pop up any message.

THANKS FOR ANY HELP

Anneke Sicherer-Roetman, Holland