0

I have a project on ubuntu and C++ and somewhere in my code there is a loop that outputs lots of data to standard output (terminal). Among these data there is an error field that I want to see its evolution as the loop iterates. For sake of clarity, consider the code below:

while (error > epsilon) {
    //do stuff
    std::cout<<foo1<<std::endl;
    std::cout<<foo2<<std::endl;

    somehow send error to gnuplot!
    //do the rest of the stuff
}

What I have in my mind is to print error to somewhere such as /dev/null and try to gnuplot it. However I'm not sure if it's possible, how to do that if possible, but above all I'm not sure if this is the proper way of doing this.

How to such task in the correct way?

Pouya
  • 1,266
  • 3
  • 18
  • 44
  • This isn't a programming question. What I think you're trying to do you can do by piping. Something like: `myprogram | gnuplot` – John Dibling Oct 29 '13 at 17:55
  • @JohnDibling, my program is printing a huge amount of data. How can I pipe one of the many numbers that it is `cout`ing to gnuplot? – Pouya Oct 29 '13 at 18:02
  • @JohnDibling, fair enough! However I should mention `pipe` in the title of the question was not referring to the `|` command. I will give it a shot meanwhile I will wait for other suggestions. Thanks. – Pouya Oct 29 '13 at 18:05
  • Please clarify the question. As I said, this doesn't look like a programming question to me. – John Dibling Oct 29 '13 at 18:07

1 Answers1

0

You could use stdout for messages and stderr for gnuplot, and pipe the latter to gnuplot using one of the tips at How to pipe stderr, and not stdout?. But this is a very nonstandard use of stderr, and so this would not be recommended except for temporary debugging use. You could also just write to a file and then plot that later.

You can use popen to open a pipe to gnuplot and send the data. The gnuplot-iostream library will help here (disclaimer: I'm the author of that).

Community
  • 1
  • 1
Dan Stahlke
  • 1,417
  • 1
  • 15
  • 20