C++ <string> Header

The C++ Standard Library provides the <string> header, which introduces string types, character traits, and a set of converting functions used for handling sequences of characters. This header facilitates the manipulation and management of strings in C++ programs.


Class Templates

  • basic_string: A generic string class template that allows for the creation and manipulation of strings with various character types.
  • char_traits: A class template that defines character traits, providing a standardized way to handle character properties and operations.

Class Instantiations

  • string: Represents a sequence of characters (i.e., a standard string) using the char type.
  • u16string: Represents a sequence of 16-bit characters, typically used for UTF-16 encoded strings.
  • u32string: Represents a sequence of 32-bit characters, commonly used for UTF-32 encoded strings.
  • wstring: Represents a wide string using the wchar_t type, suitable for internationalization.

Functions for String Conversion

Convert from Strings

  • stoi: Converts a string to an integer.
  • stol: Converts a string to a long integer.
  • stoul: Converts a string to an unsigned long integer.
  • stoll: Converts a string to a long long integer.
  • stoull: Converts a string to an unsigned long long integer.
  • stof: Converts a string to a float.
  • stod: Converts a string to a double.
  • stold: Converts a string to a long double.

Convert to Strings

  • to_string: Converts a numerical value to a standard string.
  • to_wstring: Converts a numerical value to a wide string.

Range Access Functions

  • begin: Returns an iterator to the beginning of the string.
  • end: Returns an iterator to the end of the string.