Don't use system is the first answer.
What you're doing here is asking the operating system to run a completely different application (with no link to your program - the OS simply launches the other application as if you had typed it at the command line, because that's basically what it's doing with
system); a whole different program. It could be doing anything, anything at all, and you're hoping that it will write some output to stdout, and that maybe you can intercept the output of that completely different application. This is an inherently awkward thing to do.
Your operating system provides functions for you to use to start other processes. You should use those instead. Here's a windows example to just create the process:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682512(v=vs.85).aspx
and here's one that redirects the output:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
As you can see, it's often awkward. Remember, what you're doing
is awkward. You're running a
completely different application and you're trying to capture the output from it, live.
Some third party libraries include ways of making it easier for you; QT provides QProcess, for example.