Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following program has been tested on Windows using the Visual Studio and MinGW compilers, as well as on GNU/Linux using <code>gcc</code>. The <code>gnuplot</code> binary must be on the path, and on Windows, the piped <code>pgnuplot</code> version of the binary must be used.</p> <p>I've found that Windows pipes are much slower than the corresponding ones on GNU/Linux. For large datasets, transferring data to <code>gnuplot</code> over a pipe on Windows is slow and often unreliable. Moreover, the key press waiting code is more useful on GNU/Linux, where the plot window will close once <code>pclose()</code> has been called. </p> <pre><code>#include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; // Tested on: // 1. Visual Studio 2012 on Windows // 2. Mingw gcc 4.7.1 on Windows // 3. gcc 4.6.3 on GNU/Linux // Note that gnuplot binary must be on the path // and on Windows we need to use the piped version of gnuplot #ifdef WIN32 #define GNUPLOT_NAME "pgnuplot -persist" #else #define GNUPLOT_NAME "gnuplot" #endif int main() { #ifdef WIN32 FILE *pipe = _popen(GNUPLOT_NAME, "w"); #else FILE *pipe = popen(GNUPLOT_NAME, "w"); #endif if (pipe != NULL) { fprintf(pipe, "set term wx\n"); // set the terminal fprintf(pipe, "plot '-' with lines\n"); // plot type for(int i = 0; i &lt; 10; i++) // loop over the data [0,...,9] fprintf(pipe, "%d\n", i); // data terminated with \n fprintf(pipe, "%s\n", "e"); // termination character fflush(pipe); // flush the pipe // wait for key press std::cin.clear(); std::cin.ignore(std::cin.rdbuf()-&gt;in_avail()); std::cin.get(); #ifdef WIN32 _pclose(pipe); #else pclose(pipe); #endif } else std::cout &lt;&lt; "Could not open pipe" &lt;&lt; std::endl; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload