im new to programming and was trying to understand buffers and came across : https://www.tutorialspoint.com/what-does-buffer-flush-means-in-cplusplus#:~:text=The%20buffer%20flush%20is%20used,the%20buffer%20to%20be%20written.
it said that if the buffer is not flushed, the numbers will be printed at once while it will be printed one after the other while flushing the buffer.But after trying it on my computer, they both printed one after the other.
idk this might be a silly question
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
main() {
for (int x = 1; x <= 5; ++x) {
cout << x << " " << flush;
this_thread::sleep_for(chrono::seconds(1)); //wait for 1 second
}
cout << endl;
}
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
main() {
for (int x = 1; x <= 5; ++x) {
cout << x << " ";
this_thread::sleep_for(chrono::seconds(1)); //wait for 1 second
}
cout << endl;
}