Hi guys,
As we all know, fast I/O in competitive programming is very important in speeding up our program runtime. For us C++ users, most of us will know well ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
, or instead of that, we just use scanf or printf instead.
I tried to find a library that's as functional as cout/cin and scanf/printf whilst being significantly faster and I think I found the solution: https://github.com/emeraldacoustics/fast-io. I have been using this library for quite some time now, and I think it is delivering some very nice results. I basically added the header file as template code.
The only downside is that it doesn't support dealing with strings, so we'll have to use char arrays instead. Giving it custom input is also a bit wonky, instead of entering the test input through stdin, you have to pipe it into stdin through a file, otherwise it won't run properly.
Hope you guys find this useful!
There's a simple reason why most prefer to use the normal stdio library anyways. First, it's bug-free (as far as we know). Second, it's convenient. And finally, if your solution was right, stdio wouldn't be an issue.
From using it in the past few months I haven't encountered any bugs. As to stdio not working for this library, I think it has to do with its requirement of having a set buffer size. For stdio, there isn't a set buffer size which means the program will eternally be waiting for more input. If you pipe a file to stdin, the program will run normally because there is a set buffer size, this is what online judges do as well which is why it can run fine on platforms such as CodeForces.
Just because you haven't encountered any does not mean there isn't any. One of the big reasons why stdio is not faster is because of it's sanity check
It is also conversely true. Just because I haven't experienced any doesn't mean there are bugs. I've used it in 10+ contests at this point and I have not experienced any issues, and the more I use it in, the less the probability that there is a bug.