Reputation: 37
How I can improve speeds of read & write the data from standard input (terminal) in c/c++ code?
I use:
ios::sync_with_stdio_false();
Does any way exist to do that quicker?
Upvotes: 0
Views: 234
Reputation: 137830
Obtain std::streambuf
references from std::cin.rdbuf()
and std::cout.rdbuf()
. (Yes, it's still called rdbuf
even when used for output.) Most of the slowdown in iostream occurs in the formatting functionality.
You will have to parse the bytes yourself.
As with anything performance-related, don't believe, assume, or suppose anything that doesn't come directly from profiling a run on a realistic dataset.
By the way, all bets are off if cin
or cout
are connected to any kind of terminal. The resulting graphical operations and I/O from cout
will bring the machine to its knees before your program gets a chance to run, and for cin
you would have to be a pretty fast typist.
Upvotes: 1