Call cout.flush();
before system pause. Another option would be to add and cout << endl
(as it hiddenly flushes the stream).
Flashing the result even of system pause C++
-
27-11-2021 - |
Question
Here is my code ... I want to stop it on the result, but result is showing after pressing a key ... It is flashing the result after pressing the key ... I'm using Microsoft Visual C++6.0 and windows 7.
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main() {
int a, b, n;
int danni[6][25];
cout << "n= ";
cin >> n;
for (a = 0; a < n; a++) {
for (b = 0; b < n; b++) {
cout << "danni[" << a << "][" << b << "]= ";
cin >> danni[a][b];
}
}
for (a = 0; a < n; a++) {
cout << "\n ";
for (b = 0; b < n; b++) {
//cout<<danni[a][b]<<" ";
cout << "Fak nomer: " << a << b;
}
cout << "Spec: " << a << b;
cout << "Grupa: ";
cout << a << b;
cout << "Sreden uspeh: " << a << b;
}
system("pause");
}
Solution
OTHER TIPS
Streams perform buffering. That means that they don't always write to the console as soon as you ask them to, but wait a bit more input so that they can do it in chunks and save some resources.
In this case, though, you want the stream to be totally flushed before the pause.
Write any of the following to do so:
std::cout.flush();
std::cout << std::flush;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow