Bhavya Malhotra
Bhavya Malhotra

Reputation: 23

What is the difference between ios_base::sync_with_stdio(0); and ios::sync_with_stdio(0); in C++?

My mentors in CP recommended me to use ios_base::sync_with_stdio(0); since it increases the speed of program execution. While going through some videos on YouTube, I came across ios::sync_with_stdio(0); also.

So, What difference does adding or deleting _base make?

Which is better, ios_base::sync_with_stdio(0); or ios::sync_with_stdio(0);?

Kindly explain. Thanking you in advance.

Upvotes: 2

Views: 992

Answers (1)

KamilCuk
KamilCuk

Reputation: 141165

What is the difference between ios_base::sync_with_stdio(0); and ios::sync_with_stdio(0); in C++?

One takes 5 characters more _base to type. There are no other differences.

The function is defined as a static public member function in ios_base class. ios is really typedef basic_ios<char> ios; and basic_ios inherits from ios_base. As so, ios_base::sync_with_stdio is inherited from ios_base to basic_ios<char> and to ios. It's the same function. The same way you can std::wios::sync_with_stdio or std::basic_ios<wchar_t>::sync_with_stdio etc.

For more information see cppreference io, cppreference static members, cppreference sync_with_stdio, cppreference derived classes and I always propose to read a good C++ introduction book.

Which is better, ios_base::sync_with_stdio(0); or ios::sync_with_stdio(0);?

They are equal.

Upvotes: 5

Related Questions