Good afternoon,
I wrote a Java program that runs several C ++ programs using the calls to the Process and Runtime.exec () functions. C ++ programs use cout and cin for input and output. The Java program sends information and reads information from the input stream of C ++ programs and the output stream.
Then I have a string buffer that builds what a typical program interaction would look like by adding C ++ program input and output to the string buffer. The problem is that all incoming calls are added and then all output calls are published. For example, an instance of StringBuffer might be something like this ...
2 3 Please enter two numbers to add. Your result is 5
when the program will look like this on a standard console
Please enter two numbers to add. 2 3 Your result is 5
The problem is that I get the input order and the output of all from wack, because if the C ++ program does not call the cout.flush () function, the output is not written until the input is entered.
Is there a way to automatically flush the buffer so that the C ++ program does not bother calling cout.flush ()? Just as the C ++ program was a stand-alone program that interacts with the command console, the programmer does not always need cout.flush (), the management console still displays the data before entering.
Thanks,
source share