Getting a Fast I/O stream in your CPP program
Getting a Fast I/O stream in your CPP program
Do you want a fast input and output in your CPP program, As we know C plus plus is the extended version of C language so it has the compatibility with C syntax as CPP use cin and cout for input and out respectively. But its program is compatible with printf and scanf also which cause our program input and output slow down. We may increase the speed by adding this line of code in our main function(right after definition of main)
ios_base::sync_with_stdio(false);
it will allow to turn of sync with the C input output syntax i.e. printf and scanf as now program is not synchronized with printf and scanf functions
And also we there is a synchronization between cin and cout we can turn it off also to make our input output stream fast. we can do this by adding
cin.tie(NULL);
this will turn off the synchronization between cin and cout
Lets see an example code :
#include <bits/stdc++.h>
using namespace std;
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code statements here
return 0 ;}
By adding these two lines we can make our CPP program I/O stream fast that is very helpful in Competitive programming and Projects.
Happy Coding