#include <bits/stdc++.h>
using namespace std;
void scan_a_line_indefinitely()
{
// scan line indefinitely
string input_line;
while(getline(cin,input_line))
{
cout << input_line ; **// doesn't print if i use this line**
//cout << input_line << endl; **// if i use this line, it works fine**
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
scan_a_line_indefinitely();
return 0;
}
someone please help me understand the problem with this code. i think the problem is with cout.tie() and cout.tie(), when i remove these, program works fine.
std::cout
will flush under these conditions:
An input-stream which is tied to std::cout
tries to read input.
You removed the ties.
iostreams are synchronized with stdio, thus effectively unbuffered.
You disabled the synchronization.
The buffer is full.
That takes a bit longer.
The program ends normally.
That comes too late for you.
There is a manual flush (stream.flush()
which is called when streaming std::flush
; stream << std::endl
is equivalent to stream << stream.widen('\n') << std::flush
).
You have none of those.
So, fix any of them and you will see your output earlier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With