C++ › I/O Streams

How do you improve iostream performance for large I/O?

Advanced

Answer

Techniques: call std::ios_base::sync_with_stdio(false) to decouple C++ streams from C stdio (faster but don't mix them then); untie cin from cout (std::cin.tie(nullptr)) to avoid flushing cout before each read; avoid std::endl (use '\n'); read in bulk; and for heavy formatting, prefer std::format or from_chars/to_chars. These reduce per-operation overhead.
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
Real-world example Competitive/large-data programs disable sync_with_stdio to speed up millions of cin/cout operations.

Common follow-ups: What does sync_with_stdio(false) do? | Why untie cin from cout?