Skip to content

01. What is wrong with iostream and stdio? And why use this fast_io library?

cqwrteur edited this page Apr 28, 2024 · 4 revisions

The iostream library in C++ has been a topic of debate for quite some time. While it does a few things right, it also has many issues. One of the main problems is its overuse of Object-Oriented Programming (OOP), which violates the zero-overhead principle. Additionally, iostream contributes to runtime bloat, and its performance is suboptimal. Many large C++ projects, including LLVM, GCC, Google's, and Microsoft’s, have opted to ban iostream due to these issues. Although newer C++ features can replicate some of iostream’s functionality, they lack the composability, making it challenging to find a fundamental replacement.

Regarding the alternative stdio, it also has its drawbacks. While it avoids some of iostream’s issues, it remains slow, and its mandatory locale and format string complexities have raised security concerns.

This is precisely why I initiated the fast_io library project. We need a modern alternative based on generic programming rather than traditional or Object-Oriented programming.

Furthermore, fast_io aims to preserve binary and source compatibility with iostream and stdio whenever feasible (although there are exceptions). It directly supports working with stdio and fstream’s filebuf without the overhead of construction or inconsistency. By reusing the internal buffer pointer of stdio and fstream, fast_io achieves exceptional speed compared to these libraries while also providing compatibility APIs.