Thread: good redirection strategy ???

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    good redirection strategy ???

    Hi,

    the situation is the following. I am working with a function which requires ostream to be passed into it so that it can directly print results into file od stdout.... example

    Code:
    f(ostream& stream){}
    However i don't wish to print results into either a file od stdout but rather to save them into a string . So my question is what would be the best way to achieve this "redirection" (note that i need to pass an ostream to the function ).

    thnx

    b

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Keep this and pass a stringstream.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    If you want to use the same function to print to a string why not send a ostringstream?

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strategy for a first job-job
    By doubleanti in forum General Discussions
    Replies: 5
    Last Post: 09-06-2012, 09:21 PM
  2. Help with strategy script
    By mccallum28 in forum C# Programming
    Replies: 2
    Last Post: 12-04-2011, 09:17 AM
  3. Afehganistan strategy
    By Mario F. in forum General Discussions
    Replies: 47
    Last Post: 10-31-2009, 11:34 PM
  4. What's a good Object Oriented Strategy for OpenGL/Graphics
    By indigo0086 in forum Game Programming
    Replies: 9
    Last Post: 04-03-2007, 06:27 PM
  5. Strategy Game Programming.
    By civilwarsearch in forum Game Programming
    Replies: 2
    Last Post: 01-14-2004, 02:34 PM