...

View Full Version : stream object



nappawwf
03-10-2004, 02:31 PM
i have been looking around but i cant seem to find much that would help me get going on this. what i want to do, have out put to either the screen or to a file, which will be determined at run time. instead of doing the same code for each option, is there a way to use the fostream and cout as a function arg.

raf
03-11-2004, 03:29 PM
Welcome here!

You need to ask a more precise question. What format are you talking about? HTML code? PDF? txt?
I suppose it's server side scripting, but what language?
And should the endresult be in the same or a different format for file or screen (for instance, i could print html to the screen but create a pdf-file with the same content)

For all these, there are numerous possebilitys. You could for instance generate the HTML-code, but always appent it to a variable instead of sending it to the client, and then at the end write it to a file or print it to the client, or you could then use a conversionfunction (from html to pdf, or from html to rtf or ... to store it in a different format). Or you could even first create the html and then use a html2pdf conversionfunction and send the pdf-stream to the client. Or you could just create an XML file and then use another script to convert if depending on the end-format you need. Or you could create an object and then add the content and at the end specify the method to generate the output.

What conversion or output you generate can then e determined based on a variable that you pass to this page.

shmoove
03-11-2004, 03:47 PM
Sounds like C++ to me.
In that case:
As far as I can remember (well, it's been a while) cout is an instance (a special instance, but an instance nonetheless) of the ostream, and fostream is a subclass of ostream. That means that if you're function receives an ostream parameter then you can send it either cout, or cerr, or any fostream instance you create.

shmoove

nappawwf
03-11-2004, 09:41 PM
sorry, yes it is c++, basically i wanted to have something similar to

void funct(... output)
{
output << "text" //output being either the screen or a file
}

i was looking at doing it with pointers, but im rather behind on those

shmoove
03-12-2004, 11:36 AM
And did you try:


void funct(ostream output)
{
output << "text" //output being either the screen or a file
}

Like I said, I'm a little rusty on my C++, but since both cout and a fostream are derived from the same base class, something like that (after you clean it from any bugs), should work.

shmoove

nappawwf
03-13-2004, 01:12 AM
yeah that did the trick, thanks a lot



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum