[string.syn]

# 27 Strings library [[strings]](./#strings)

## 27.4 String classes [[string.classes]](string.classes#string.syn)

### 27.4.2 Header <string> synopsis [string.syn]

#include <compare> // see [[compare.syn]](compare.syn "17.12.1 Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2 Header <initializer_­list> synopsis")namespace std {// [[char.traits]](char.traits "27.2 Character traits"), character traitstemplate<class charT> struct char_traits; // freestandingtemplate<> struct char_traits<char>; // freestandingtemplate<> struct char_traits<char8_t>; // freestandingtemplate<> struct char_traits<char16_t>; // freestandingtemplate<> struct char_traits<char32_t>; // freestandingtemplate<> struct char_traits<wchar_t>; // freestanding// [[basic.string]](basic.string "27.4.3 Class template basic_­string"), basic_stringtemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_string; template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(basic_string<charT, traits, Allocator>&& lhs, const basic_string<charT, traits, Allocator>& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const basic_string<charT, traits, Allocator>& lhs,
 basic_string<charT, traits, Allocator>&& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(basic_string<charT, traits, Allocator>&& lhs,
 basic_string<charT, traits, Allocator>&& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const charT* lhs,
 basic_string<charT, traits, Allocator>&& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(charT lhs, const basic_string<charT, traits, Allocator>& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(charT lhs,
 basic_string<charT, traits, Allocator>&& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(basic_string<charT, traits, Allocator>&& lhs, const charT* rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const basic_string<charT, traits, Allocator>& lhs,
 charT rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(basic_string<charT, traits, Allocator>&& lhs,
 charT rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(const basic_string<charT, traits, Allocator>& lhs,
 type_identity_t<basic_string_view<charT, traits>> rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(basic_string<charT, traits, Allocator>&& lhs,
 type_identity_t<basic_string_view<charT, traits>> rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(type_identity_t<basic_string_view<charT, traits>> lhs, const basic_string<charT, traits, Allocator>& rhs); template<class charT, class traits, class Allocator>constexpr basic_string<charT, traits, Allocator>operator+(type_identity_t<basic_string_view<charT, traits>> lhs,
 basic_string<charT, traits, Allocator>&& rhs); template<class charT, class traits, class Allocator>constexpr booloperator==(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; template<class charT, class traits, class Allocator>constexpr bool operator==(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); template<class charT, class traits, class Allocator>constexpr *see below* operator<=>(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; template<class charT, class traits, class Allocator>constexpr *see below* operator<=>(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // [[string.special]](string.special "27.4.4.3 swap"), swaptemplate<class charT, class traits, class Allocator>constexpr void swap(basic_string<charT, traits, Allocator>& lhs,
 basic_string<charT, traits, Allocator>& rhs)noexcept(noexcept(lhs.swap(rhs))); // [[string.io]](string.io "27.4.4.4 Inserters and extractors"), inserters and extractorstemplate<class charT, class traits, class Allocator> basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is,
 basic_string<charT, traits, Allocator>& str); template<class charT, class traits, class Allocator> basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>& is,
 basic_string<charT, traits, Allocator>& str,
 charT delim); template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>&& is,
 basic_string<charT, traits, Allocator>& str,
 charT delim); template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>& is,
 basic_string<charT, traits, Allocator>& str); template<class charT, class traits, class Allocator> basic_istream<charT, traits>& getline(basic_istream<charT, traits>&& is,
 basic_string<charT, traits, Allocator>& str); // [[string.erasure]](string.erasure "27.4.4.5 Erasure"), erasuretemplate<class charT, class traits, class Allocator, class U = charT>constexpr typename basic_string<charT, traits, Allocator>::size_type
 erase(basic_string<charT, traits, Allocator>& c, const U& value); template<class charT, class traits, class Allocator, class Predicate>constexpr typename basic_string<charT, traits, Allocator>::size_type
 erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // basic_string [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]")*s*using [string](#lib:string "27.4.2 Header <string> synopsis [string.syn]") = basic_string<char>; using [u8string](#lib:u8string "27.4.2 Header <string> synopsis [string.syn]") = basic_string<char8_t>; using [u16string](#lib:u16string "27.4.2 Header <string> synopsis [string.syn]") = basic_string<char16_t>; using [u32string](#lib:u32string "27.4.2 Header <string> synopsis [string.syn]") = basic_string<char32_t>; using [wstring](#lib:wstring "27.4.2 Header <string> synopsis [string.syn]") = basic_string<wchar_t>; // [[string.conversions]](string.conversions "27.4.5 Numeric conversions"), numeric conversionsint stoi(const string& str, size_t* idx = nullptr, int base = 10); long stol(const string& str, size_t* idx = nullptr, int base = 10); unsigned long stoul(const string& str, size_t* idx = nullptr, int base = 10); long long stoll(const string& str, size_t* idx = nullptr, int base = 10); unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10); float stof(const string& str, size_t* idx = nullptr); double stod(const string& str, size_t* idx = nullptr); long double stold(const string& str, size_t* idx = nullptr);
 string to_string(int val);
 string to_string(unsigned val);
 string to_string(long val);
 string to_string(unsigned long val);
 string to_string(long long val);
 string to_string(unsigned long long val);
 string to_string(float val);
 string to_string(double val);
 string to_string(long double val); int stoi(const wstring& str, size_t* idx = nullptr, int base = 10); long stol(const wstring& str, size_t* idx = nullptr, int base = 10); unsigned long stoul(const wstring& str, size_t* idx = nullptr, int base = 10); long long stoll(const wstring& str, size_t* idx = nullptr, int base = 10); unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10); float stof(const wstring& str, size_t* idx = nullptr); double stod(const wstring& str, size_t* idx = nullptr); long double stold(const wstring& str, size_t* idx = nullptr);
 wstring to_wstring(int val);
 wstring to_wstring(unsigned val);
 wstring to_wstring(long val);
 wstring to_wstring(unsigned long val);
 wstring to_wstring(long long val);
 wstring to_wstring(unsigned long long val);
 wstring to_wstring(float val);
 wstring to_wstring(double val);
 wstring to_wstring(long double val); namespace pmr {template<class charT, class traits = char_traits<charT>>using basic_string = std::basic_string<charT, traits, polymorphic_allocator<charT>>; using string = basic_string<char>; using u8string = basic_string<char8_t>; using u16string = basic_string<char16_t>; using u32string = basic_string<char32_t>; using wstring = basic_string<wchar_t>; }// [[basic.string.hash]](basic.string.hash "27.4.6 Hash support"), hash supporttemplate<class T> struct hash; template<class A> struct hash<basic_string<char, char_traits<char>, A>>; template<class A> struct hash<basic_string<char8_t, char_traits<char8_t>, A>>; template<class A> struct hash<basic_string<char16_t, char_traits<char16_t>, A>>; template<class A> struct hash<basic_string<char32_t, char_traits<char32_t>, A>>; template<class A> struct hash<basic_string<wchar_t, char_traits<wchar_t>, A>>; inline namespace literals {inline namespace string_literals {// [[basic.string.literals]](basic.string.literals "27.4.7 Suffix for basic_­string literals"), suffix for basic_string literalsconstexpr string operator""s(const char* str, size_t len); constexpr u8string operator""s(const char8_t* str, size_t len); constexpr u16string operator""s(const char16_t* str, size_t len); constexpr u32string operator""s(const char32_t* str, size_t len); constexpr wstring operator""s(const wchar_t* str, size_t len); }}}
