The program calls a function that outputs the result of the work to FILE* . The function call looks like this:

 gvRender (gvc, g, "svg", stdout); 

You must redirect the output from stdout to a string or QString , without using a write to the file. How to do it better?

  • one
    Perhaps QProcess ? - PinkTux
  • In the case of the graphviz library, in which the functions begin with <gv>, it turned out that there is a separate function that sends the result to the string. This is gvRenderData () - Roman Gin

1 answer 1

If I understood the question correctly, then you can reassign stream buffers. Example:

 #include <iostream> #include <sstream> int main() { std::ostringstream ss; auto cout_buff = std::cout.rdbuf(); // сохраняем родной буфер cout std::cout.rdbuf(ss.rdbuf()); // перенаправляем вывод в строковой поток std::cout << "hello\n"; // реально печатает в строку (на экране ещё пусто) std::cout.rdbuf(cout_buff); // возвращаем родной буфер std::cout << ss.str(); // выводим содержимое строки } 

If you need to reassign the sdish stdout to another file, you can use freopen . Some options can be found in the enSO question .

  • Thank! It Works - Roman Gin
  • one
    Explain why, if Qt has native tools? - PinkTux
  • @PinkTux native for what? - αλεχολυτ 7:16 pm
  • @alexolut, for Qt :) In one direction, I poked in the comment to the question. On it you can instantly go to the second: QTextStream. - PinkTux
  • @PinkTux so write the answer or something. :) - αλεχολυτ 7:49 pm