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
- stringstream debug;
- debug<<"Debug message"<<endl;
- //create another thread that might output debug message
- MyThread *th = new MyThread(debug);
- th->start();
- //for now output debug message to stdout whenever possible
- while(debug)
- {
- char c;
- debug.get(c);
- if(debug) cout<<c;
- }
I will be really grateful if you can help me on this problem. Thank you very much!