Input/output library

Curated hub for C++ I/O: stream foundations, file and string streams, print-oriented output, syncstream, and C-style compatibility.

C++ I/O spans several models: classic stream extraction/insertion, file streams, string-backed streams, newer span-backed streams, synchronized output, and modern print-oriented functions. This hub helps you choose the right I/O route first, then drill into the concrete stream or helper type you actually need.

Use this page for I/O models and navigation. Keep filesystem as the path/filesystem hub, string for textual storage and views, and format for formatting semantics rather than stream transport.

# Start Here

Console and standard streams

Start here when you are writing to or reading from the standard process streams and want the usual stream insertion/extraction workflow.

File streams

Use stream-based file I/O when you want typed extraction/insertion, stream state management, and buffered file access.

String-backed streams

Choose string streams when you want stream formatting/parsing over an in-memory string buffer instead of a file or console stream.

Span-backed streams

Use span streams for stream-style operations over an existing span buffer without owning the underlying storage.

Modern formatted output

Prefer print-oriented APIs when you want direct formatted output without building a stream insertion pipeline manually.

C compatibility I/O

Use the C-style surface when you need `FILE*`, `printf`/`scanf`-style APIs, or compatibility with existing C code.

# I/O Models

ModelStart withUse it for
Stream foundationsios_base, basic_ios, basic_streambufUnderstanding stream state, formatting flags, locale interaction, ties, and buffer mechanics.
Standard process streamscout, cin, cerr, clogInteractive console input/output and process-level logging/error channels.
File streamsifstream, ofstream, fstreamBuffered file input, output, and read/write stream access with stream semantics.
String streamsistringstream, ostringstream, stringstreamParsing or formatting text in memory using the stream interface.
Span-backed streamsspanstream, ispanstream, ospanstreamStream-style access over existing contiguous storage, especially when you want non-owning buffers.
Print-oriented outputprint, printlnDirect formatted output using the modern format-based model instead of stream insertion chains.
Synchronized outputbasic_osyncstreamCoordinating output from multiple threads without interleaving chunks unpredictably.
C compatibilityC I/O`FILE*`-based APIs, compatibility with C code, and traditional formatted I/O families.

# Quick Choice Map

If you need...Start withWhyCommon alternative
Formatted console output in existing stream-heavy codecout and ostreamThe standard insertion model integrates directly with manipulators and stream state.print
Direct formatted output with less stream boilerplateprint or printlnUses the modern formatting route and is often simpler when you only need output.cout, format
File-based text or binary streamingifstream, ofstream, or fstreamThey provide typed stream operations and file ownership on top of file buffers.C I/O, filesystem
Parsing from or formatting to a `std::string`istringstream, ostringstream, or stringstreamLets you reuse the stream extraction/insertion model entirely in memory.format, string utilities
Stream-style operations over a borrowed bufferspanstream and related span stream typesUseful when a stream interface is convenient but you do not want string ownership or file handles.stringstream, span
Thread-safe grouped outputbasic_osyncstreamBuffers output chunks and emits them atomically to the wrapped stream.cout, print
Legacy or C interoperability with `FILE*`C I/ORequired when working with traditional C APIs or `printf`/`scanf` style code.filebuf, fstream

# Modern Vs. Legacy Routes

Use casePreferred modern routeLegacy or older route
Formatted terminal or file outputprint, println, ostreamC I/O and manual `printf`-style formatting
In-memory stream processingstringstream, spanstreamstrstream, istrstream, ostrstream, strstreambuf
Concurrent output to a shared streambasic_osyncstreamManual locking around plain ostream operations
Path-oriented file workfilesystem plus file streams when neededMixing all file/path concerns directly into stream-only code

# Support Types And Stream Plumbing

AreaKey pagesWhy you visit it
Formatting flags and stream stateios_base, basic_iosWhen extraction/insertion behavior depends on flags, locale, fill characters, or error bits.
Underlying bufferingbasic_streambuf, basic_filebuf, basic_stringbuf, basic_spanbufWhen you need lower-level control over the storage or transport behind a stream interface.
Manipulators and offsetsmanipulators, fpos, streamoff, streamsizeWhen formatting, positioning, or size/offset types matter directly.
I/O error categoriesio_errcWhen integrating stream errors with the broader `error_code` model.

Filesystem

Use filesystem for path manipulation, directory traversal, file status, and file operations outside stream mechanics.

Format

Use the formatting library when your main question is format-string semantics or formatter customization rather than I/O transport.

String

Use the string hub for owning strings, views, character encodings, literals, and conversions rather than stream wrappers.

Diagnostics

Use diagnostics for exception types, `error_code`, and broader runtime error handling adjacent to I/O failures.

# See also