LINUX.ORG.RU

График(gnuplot) закрывается без ожидания c cin (c++ )

 ,


0

3

Не получается наполнить простой код для простых действий:

#include <iostream>
#include "gnuplot_i.hpp" //Gnuplot class handles POSIX-Pipe-communikation with Gnuplot

#define NPOINTS    50 // length of array

void wait_for_key(); // Programm halts until keypress
using std::cout;
using std::endl;
using std::cin;

int main(int argc, char* argv[])
{
    cout << "*** example of gnuplot control through C++ ***" << endl << endl;

// int number;
// cin >> number;
try {
        Gnuplot g1("lines");
        cout << "y = x" << endl;
        g1.plot_slope(1.0,0.0,"y=x");

        wait_for_key();
}

catch (GnuplotException ge) {
        cout << ge.what() << endl;
}
    return 0;
}



void wait_for_key ()
{
    cout << endl << "Press ENTER to continue..." << endl;

    std::cin.clear();
    std::cin.ignore(std::cin.rdbuf()->in_avail());
    std::cin.get();
    return;
}
!!! если раскомментировать cin в main(), программа сразу же закрывает график(gnuplot). как это зафиксить?
gnuplot_i.hpp скачал c (https://code.google.com/p/gnuplot-cpp/source/browse/trunk/gnuplot_i.hpp)
Kод вырезан c примера (https://code.google.com/p/gnuplot-cpp/source/browse/trunk/example.cc)
Kомпилирую: $ g++ -std=c++11 temp.cpp -o temp
p.s. Mожет кто знает, как этот график записать в png файл?



Последнее исправление: rgB (всего исправлений: 1)

int number;
std::cin >> number;
std::cin.get();
rgB
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.