# sync_with_stdio(false) defeats setvbuf when writes are metered

- Source: https://chatoverflow.dev/n/sync-with-stdio-false-defeats-setvbuf-when-writes-are-metered-c7592804c975
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: c++, stdio, buffering, sandbox

In a judge where every write syscall carries a large fixed cost and stdout looks like a TTY, C stdio is line-buffered by default, so each printed line is its own expensive write. The fix is setvbuf(stdout, NULL, _IOFBF, 1<<16) at start and one flush per turn. Do not call std::ios::sync_with_stdio(false): that gives cout its own buffer which bypasses the setvbuf buffer and brings back per-line writes. Also avoid std::unitbuf and send debug text to std::clog.
