Strings library

Owning strings, string views, character traits, literals, conversions, and adjacent text/encoding routes.

The C++ strings area spans owning string containers, non-owning views, character traits, literals, null-terminated compatibility APIs, and newer text-encoding adjacent facilities. This page is the curated starting point when you know your problem is “text-like”, but you still need the right model.

This hub focuses on choosing the right string surface. It does not duplicate the full member indexes of basic_string or basic_string_view, and it keeps broader I/O, locale, and formatting topics linked as adjacent destinations.

# Start Here

Owning strings

Use std::basic_string and its aliases when the string owns its storage, needs mutation, or must outlive the source buffer it came from.

Non-owning views

Use std::basic_string_view when you want to read from an existing character sequence without copying it and can guarantee the referenced storage stays alive.

String literals and character kinds

Start here when the issue is about literal syntax, prefixes, encodings, or choosing between char, wchar_t, char8_t, char16_t, and char32_t.

Null-terminated compatibility APIs

Use the byte, multibyte, and wide-string families when you need C-compatible interfaces, locale-sensitive conversions, or legacy NTBS-style algorithms.

# Quick Map

If you need toStart withWhy
Store and mutate text with owned lifetimebasic_stringIt owns storage, supports mutation, growth, searching, replacement, and the standard string aliases such as std::string and std::u8string.
Pass read-only text around without copyingbasic_string_viewIt models a lightweight non-owning view over contiguous characters, but the caller must manage lifetime carefully.
Convert numbers to or from stringsto_string, stoi/stol/stoll, stof/stod/stoldThese are the string-focused conversion helpers; use to_chars and from_chars for lower-level locale-independent conversion.
Choose the right literal form or suffixString literals, basic_string, basic_string_viewLiterals determine character type, encoding form, and whether the result is an array, an owning string, or a string_view.
Work with C-compatible null-terminated stringsByte strings, Wide strings, MultibyteThese sections hold the NTBS-style and locale-sensitive APIs that remain important for interoperability and lower-level text handling.
Understand encodings, character traits, or text model boundarieschar_traits, Character sets, text_encodingThese pages explain how character operations are abstracted and how encoding-aware code relates to literal and runtime environments.

# Core String Models

ModelUse it whenPrimary destinations
Owning dynamic stringYou need allocation, mutation, append/replace operations, or independent lifetime.basic_string, constructors, concatenation
Non-owning string viewYou need a cheap parameter or slice type over existing text and can guarantee the source buffer remains valid.basic_string_view, substr, remove_prefix
Character operation policyYou need generic character comparison/copy/length behavior for a string-like type.char_traits
C-compatible null-terminated stringsYou are interoperating with legacy APIs, locale conversion routines, or NTBS-style algorithms.byte, multibyte, wide

# Character Types And Encodings

Literal forms

String literal prefixes choose the code unit type and affect whether you start from ordinary, wide, UTF-8, UTF-16, or UTF-32 literal data.

Character sets

Use the language charset page when the question is about source, execution, ordinary, or wide literal encodings rather than a particular string container.

Runtime encoding identity

std::text_encoding is the modern route for reasoning about literal, locale, and environment encoding identities at compile time and runtime.

# Conversion And Formatting Routes

TaskPreferred routeRelated route
Numeric value to stringto_string, to_wstringformat for richer formatting, to_chars for lower-level conversion
String to integerstoi/stol/stoll, stoul/stoullfrom_chars when you want locale-independent parsing with tighter control
String to floating-pointstof/stod/stoldfrom_chars for low-level parsing paths
Stream a string-like objectbasic_stringstream, stream operatorsI/O hub for broader stream model choices

# Version Highlights

StandardWhat changed navigation-wise
C++11User-defined string literal suffixes, new conversion helpers like to_string, and the UTF-16/UTF-32 character families became part of the main modern string story.
C++17string_view became the default non-owning route, which materially changes API design and parameter-passing choices.
C++20char8_t and UTF-8-specific aliases became first-class, making the choice of character type and literal prefix more visible than before.
C++23More string/view convenience APIs such as contains and ranges-aware member additions reduce the need for ad hoc helper code.
C++26text_encoding gives the strings/text area a clearer runtime encoding-identification entry point, and to_string aligns more closely with modern formatting behavior.

# Boundary Lines

This hub coversUse a different hub for
Owning strings, string views, traits, literals, NTBS compatibility, and string-specific conversions.Text for the dedicated text-encoding surface, I/O for stream architecture, Utility for formatting and char-conversion primitives, Locale for locale facets and localization behavior.
C++ string abstractions over character sequences.C string when you need the C-side library surface or cross-language compatibility details.