Search code examples
c++c++17stdio

Why "ios::sync_with_studio(0) and cin.tie(0);" doesn't work with strings in C++


I was solving one problem using C++ where I have to take a string as an input. So instead of using the standard input/output method, I tried to use fast input/output method.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_studio(0);
    cin.tie(0);
 
    string str;
    cin>>str;
    cout<<str;
    return 0;
}

it shows an error:-

error: 'sync_with_studio' is not a member of 'std::ios {aka std::basic_ios<char>}'
     ios::sync_with_studio(0);
     ^~~

but if I use

ios_base::sync_with_stdio(false);
cin.tie(NULL);

it worked. can someone tell why the above code doesn't work and why this work


Solution

  • That's the way it is. You need to make sure that you're writing the names correctly. You can always take a look at https://en.cppreference.com/w/.

    But in this case, check this: std::ios_base::sync_with_stdio

    Also keep in mind that if set to false, the C++ standard stream objects such as cout, clog, cerr, wcout, etc. will not be synchronized and you might see unexpectedly interleaved output if you mix them.