Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

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.

question from:https://stackoverflow.com/questions/65625992/what-is-the-difference-between-ios-basesync-with-stdio0-and-iossync-with

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...