469,950 Members | 1,880 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

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


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;
  4. //create another thread that might output debug message
  5. MyThread *th = new MyThread(debug);
  6. th->start();
  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. }
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
0 1209

Post your reply

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

Similar topics

6 posts views Thread by Giampiero Gabbiani | last post: by
1 post views Thread by KidLogik | last post: by
4 posts views Thread by Dylan | last post: by
5 posts views Thread by Marcin Kalicinski | last post: by
1 post views Thread by magix | last post: by
2 posts views Thread by akitoto | last post: by
7 posts views Thread by Grey Alien | last post: by
3 posts views Thread by Rune Allnor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.