Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: stream object

  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stream object

    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.

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And did you try:
    Code:
    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

  • #6
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah that did the trick, thanks a lot


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •