By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,409 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

How to use std::stringstream create flexible debug stream?

P: 1
Hi!

I am writing a program for the robot that runs as a daemon on a linux machine. Since debug output cannot be seen on stdout, I want to create an iostream to handle all the output messages. However, I do not want to use a file or output to the clog since I want to achieve the debug message remotely through TCP connection. I've already built a TCP server for transmitting data, all i need is an "endless" stringstream.

I tried to code this way:

Expand|Select|Wrap|Line Numbers
  1. stringstream debug;
  2. debug<<"Debug message"<<endl;
  3.  
  4. //create another thread that might output debug message
  5. MyThread *th = new MyThread(debug);
  6. th->start();
  7.  
  8. //for now output debug message to stdout whenever possible
  9. while(debug)
  10. {
  11.   char c;
  12.   debug.get(c);
  13.   if(debug) cout<<c;
  14. }
  15.  
The problem is, after reading the first line of debug message ("Debug message"), stringstream thinks that we reached an end which is not what I want. I want that somehow the stringstream becomes "endless", and blocks when trying to read from empty buffer.

I will be really grateful if you can help me on this problem. Thank you very much!
Mar 21 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.