What is the significance of including this in C++ programs?
std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); In my tests, it speeds up the execution time, but is there a test case I should be worried about by including this?
Do the 2 statements always have to be together, or is the first one sufficient, i.e. omitting std::cin.tie(nullptr)?
Also, is it permissible to use simultaneous C stdio and C++ iostream functions if sync_with_stdio has been set to false?
This below test-case worked fine until I used scanf/printf in a C++ program with the value as true. In this case, it gave a segmentation fault. What could be the possible explanation for this?
#include<iostream> #include<stdio.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int w; scanf("%d",&w); char crap=getchar(); while(w--){ string a; getline(cin,a); int t=1,i; if((a.length()==1)||(a.length()==2)) printf("Bad\n"); else{ for(i=0;i<a.length()-2;i++){ if(((a[i]=='0')&&(a[i+1]=='1')&&(a[i+2]=='0'))||((a[i]=='1')&&(a[i+1]=='0')&&(a[i+2]=='1'))){ t=1; break; } else t=0; } if(t==0) printf("Bad\n"); else printf("Good\n"); } } return 0; }