Пространства имён
Варианты
Действия

Заголовочный файл стандартной библиотеки <string>

Материал из cppreference.com
< cpp‎ | header
 
 
Заголовочные файлы стандартной библиотеки
Языковая поддержка
Концепты
<concepts>(C++20)
Диагностика
Управление памятью
Метапрограммирование
<ratio>(C++11)
Общие утилиты
<charconv>(C++17)
<format>(C++20)
<bit>(C++20)

Строки
<string_view>(C++17)
<string>
<cuchar>(C++11)

Контейнеры
<flat_set>(C++23)
<span>(C++20)
<mdspan>(C++23)

Итераторы
<iterator>
Диапазоны
<ranges>(C++20)
Алгоритмы
Числа
<numbers>(C++20)

Время
<chrono>(C++11)
Локализация
<codecvt>(C++11/17*)
Ввод/вывод
Регулярные выражения
<regex>(C++11)
Поддержка конкуренции
<stop_token>(C++20)
<thread>(C++11)
<atomic>(C++11)
<barrier>(C++20)
<future>(C++11)

Совместимость с C
<cstdbool>(C++11/17/20*)  
<ccomplex>(C++11/17/20*)
<ctgmath>(C++11/17/20*)

<cstdalign>(C++11/17/20*)

<ciso646>(до C++20)

 

Этот заголовок является частью библиотеки строк.

Содержание

Включает

(C++20)
Поддержка оператора трёхстороннего сравнения[править]
Шаблонный класс std::initializer_list[править]

Классы

Шаблонный класс, описывающий свойства символьного типа
(шаблон класса)
std::char_traits<char>(специализация шаблона класса)
std::char_traits<wchar_t>(специализация шаблона класса)
std::char_traits<char8_t>(C++20)(специализация шаблона класса)
std::char_traits<char16_t>(C++11)(специализация шаблона класса)
std::char_traits<char32_t>(C++11)(специализация шаблона класса)
хранит и управляет последовательностями символов
(шаблон класса)[править]
std::stringstd::basic_string<char>(определение типа)
std::u8string(C++20)std::basic_string<char8_t>(определение типа)
std::u16string(C++11)std::basic_string<char16_t>(определение типа)
std::u32string(C++11)std::basic_string<char32_t>(определение типа)
std::wstringstd::basic_string<wchar_t>(определение типа)
std::pmr::basic_string(C++17)(псевдоним шаблона)
std::pmr::string(C++17)std::pmr::basic_string<char>(определение типа)
std::pmr::u8string(C++20)std::pmr::basic_string<char8_t>(определение типа)
std::pmr::u16string(C++17)std::pmr::basic_string<char16_t>(определение типа)
std::pmr::u32string(C++17)std::pmr::basic_string<char32_t>(определение типа)
std::pmr::wstring(C++17)std::pmr::basic_string<wchar_t>(определение типа)
поддержка хэширования для строк
(специализация шаблона класса)

Функции

объединяет две строки или строку и символ
(шаблон функции)[править]
(удалено в C++20)(удалено в C++20)(удалено в C++20)(удалено в C++20)(удалено в C++20)(C++20)
лексикографически сравнивает две строки
(шаблон функции)[править]
специализация алгоритма std::swap
(шаблон функции)[править]
удаляет все элементы, соответствующие определённым критериям
(шаблон функции)[править]
Ввод/Вывод
выполняет потоковый ввод и вывод для строк
(шаблон функции)[править]
считывает данные из потока ввода-вывода в строку
(шаблон функции)[править]
Числовые преобразования
(C++11)(C++11)(C++11)
преобразует строку в целое число со знаком
(функция)[править]
(C++11)(C++11)
преобразует строку в целое число без знака
(функция)[править]
(C++11)(C++11)(C++11)
преобразует строку в значение с плавающей запятой
(функция)[править]
(C++11)
преобразует целое значение или значение с плавающей запятой в string
(функция)[править]
(C++11)
преобразует целое значение или значение с плавающей запятой в wstring
(функция)[править]
Доступ к диапазонам
(C++11)(C++14)
возвращает итератор на начало контейнера или массива
(шаблон функции)[править]
(C++11)(C++14)
возвращает итератор на конец контейнера или массива
(шаблон функции)[править]
возвращает обратный итератор на начало контейнера или массива
(шаблон функции)[править]
(C++14)
возвращает обратный конечный итератор для контейнера или массива
(шаблон функции)[править]
(C++17)(C++20)
возвращает размер контейнера или массива
(шаблон функции)[править]
(C++17)
проверяет, пустой ли контейнер
(шаблон функции)[править]
(C++17)
получает указатель на базовый массив
(шаблон функции)[править]
Литералы
Определены в пространстве имён std::literals::string_literals
Преобразует литерал символьного массива в basic_string
(функция)[править]

[править]Резюме

#include <compare>#include <initializer_list>   namespace std {// свойства символовtemplate<class CharT>struct char_traits;// автономнаяtemplate<>struct char_traits<char>;// автономнаяtemplate<>struct char_traits<char8_t>;// автономнаяtemplate<>struct char_traits<char16_t>;// автономнаяtemplate<>struct char_traits<char32_t>;// автономнаяtemplate<>struct char_traits<wchar_t>;// автономная   // 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>constexprbool operator==(const basic_string<CharT, Traits, Allocator>& lhs, const basic_string<CharT, Traits, Allocator>& rhs)noexcept;template<class CharT, class Traits, class Allocator>constexprbool operator==(const basic_string<CharT, Traits, Allocator>& lhs, const CharT* rhs);   template<class CharT, class Traits, class Allocator>constexpr/* смотрите описание */ operator<=>(const basic_string<CharT, Traits, Allocator>& lhs, const basic_string<CharT, Traits, Allocator>& rhs)noexcept;template<class CharT, class Traits, class Allocator>constexpr/* смотрите описание */ operator<=>(const basic_string<CharT, Traits, Allocator>& lhs, const CharT* rhs);   // обменtemplate<class CharT, class Traits, class Allocator>constexprvoid swap(basic_string<CharT, Traits, Allocator>& lhs, basic_string<CharT, Traits, Allocator>& rhs)noexcept(noexcept(lhs.swap(rhs)));   // вставка и извлечениеtemplate<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);   // удалениеtemplate<class CharT, class Traits, class Allocator, class U>constexprtypename 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 Pred>constexprtypename basic_string<CharT, Traits, Allocator>::size_type erase_if(basic_string<CharT, Traits, Allocator>& c, Pred pred);   // имена типов basic_stringusing 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>;   // числовые преобразованияint stoi(const string& str, size_t* idx = nullptr, int base =10);long stol(const string& str, size_t* idx = nullptr, int base =10);unsignedlong stoul(const string& str, size_t* idx = nullptr, int base =10);longlong stoll(const string& str, size_t* idx = nullptr, int base =10);unsignedlonglong 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);longdouble 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(unsignedlong val); string to_string(longlong val); string to_string(unsignedlonglong val); string to_string(float val); string to_string(double val); string to_string(longdouble 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);unsignedlong stoul(const wstring& str, size_t* idx = nullptr, int base =10);longlong stoll(const wstring& str, size_t* idx = nullptr, int base =10);unsignedlonglong 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);longdouble 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(unsignedlong val); wstring to_wstring(longlong val); wstring to_wstring(unsignedlonglong val); wstring to_wstring(float val); wstring to_wstring(double val); wstring to_wstring(longdouble 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>;}   // поддержка хэшированияtemplate<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>>;   inlinenamespace literals {inlinenamespace string_literals {// суффикс для литералов basic_stringconstexpr string operator""s(constchar* str, size_t len);constexpr u8string operator""s(const char8_t* str, size_t len);constexpr u16string operator""s(constchar16_t* str, size_t len);constexpr u32string operator""s(constchar32_t* str, size_t len);constexpr wstring operator""s(constwchar_t* str, size_t len);}}}

[править]Шаблонный класс std::char_traits

namespace std {template<>struct char_traits<char>{using char_type =char;using int_type =int;using off_type = streamoff;using pos_type = streampos;using state_type = mbstate_t;using comparison_category = strong_ordering;   staticconstexprvoid assign(char_type& c1, const char_type& c2)noexcept;staticconstexprbool eq(char_type c1, char_type c2)noexcept;staticconstexprbool lt(char_type c1, char_type c2)noexcept;   staticconstexprint compare(const char_type* s1, const char_type* s2, size_t n);staticconstexpr size_t length(const char_type* s);staticconstexprconst char_type* find(const char_type* s, size_t n, const char_type& a);staticconstexpr char_type* move(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* copy(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* assign(char_type* s, size_t n, char_type a);   staticconstexpr int_type not_eof(int_type c)noexcept;staticconstexpr char_type to_char_type(int_type c)noexcept;staticconstexpr int_type to_int_type(char_type c)noexcept;staticconstexprbool eq_int_type(int_type c1, int_type c2)noexcept;staticconstexpr int_type eof()noexcept;};   template<>struct char_traits<char8_t>{using char_type = char8_t;using int_type =unsignedint;using off_type = streamoff;using pos_type = u8streampos;using state_type = mbstate_t;using comparison_category = strong_ordering;   staticconstexprvoid assign(char_type& c1, const char_type& c2)noexcept;staticconstexprbool eq(char_type c1, char_type c2)noexcept;staticconstexprbool lt(char_type c1, char_type c2)noexcept;   staticconstexprint compare(const char_type* s1, const char_type* s2, size_t n);staticconstexpr size_t length(const char_type* s);staticconstexprconst char_type* find(const char_type* s, size_t n, const char_type& a);staticconstexpr char_type* move(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* copy(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* assign(char_type* s, size_t n, char_type a);staticconstexpr int_type not_eof(int_type c)noexcept;staticconstexpr char_type to_char_type(int_type c)noexcept;staticconstexpr int_type to_int_type(char_type c)noexcept;staticconstexprbool eq_int_type(int_type c1, int_type c2)noexcept;staticconstexpr int_type eof()noexcept;};   template<>struct char_traits<char16_t>{using char_type =char16_t;using int_type = uint_least16_t;using off_type = streamoff;using pos_type = u16streampos;using state_type = mbstate_t;using comparison_category = strong_ordering;   staticconstexprvoid assign(char_type& c1, const char_type& c2)noexcept;staticconstexprbool eq(char_type c1, char_type c2)noexcept;staticconstexprbool lt(char_type c1, char_type c2)noexcept;   staticconstexprint compare(const char_type* s1, const char_type* s2, size_t n);staticconstexpr size_t length(const char_type* s);staticconstexprconst char_type* find(const char_type* s, size_t n, const char_type& a);staticconstexpr char_type* move(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* copy(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* assign(char_type* s, size_t n, char_type a);   staticconstexpr int_type not_eof(int_type c)noexcept;staticconstexpr char_type to_char_type(int_type c)noexcept;staticconstexpr int_type to_int_type(char_type c)noexcept;staticconstexprbool eq_int_type(int_type c1, int_type c2)noexcept;staticconstexpr int_type eof()noexcept;};   template<>struct char_traits<char32_t>{using char_type =char32_t;using int_type = uint_least32_t;using off_type = streamoff;using pos_type = u32streampos;using state_type = mbstate_t;using comparison_category = strong_ordering;   staticconstexprvoid assign(char_type& c1, const char_type& c2)noexcept;staticconstexprbool eq(char_type c1, char_type c2)noexcept;staticconstexprbool lt(char_type c1, char_type c2)noexcept;   staticconstexprint compare(const char_type* s1, const char_type* s2, size_t n);staticconstexpr size_t length(const char_type* s);staticconstexprconst char_type* find(const char_type* s, size_t n, const char_type& a);staticconstexpr char_type* move(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* copy(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* assign(char_type* s, size_t n, char_type a);   staticconstexpr int_type not_eof(int_type c)noexcept;staticconstexpr char_type to_char_type(int_type c)noexcept;staticconstexpr int_type to_int_type(char_type c)noexcept;staticconstexprbool eq_int_type(int_type c1, int_type c2)noexcept;staticconstexpr int_type eof()noexcept;};   template<>struct char_traits<wchar_t>{using char_type =wchar_t;using int_type = wint_t;using off_type = streamoff;using pos_type = wstreampos;using state_type = mbstate_t;using comparison_category = strong_ordering;   staticconstexprvoid assign(char_type& c1, const char_type& c2)noexcept;staticconstexprbool eq(char_type c1, char_type c2)noexcept;staticconstexprbool lt(char_type c1, char_type c2)noexcept;   staticconstexprint compare(const char_type* s1, const char_type* s2, size_t n);staticconstexpr size_t length(const char_type* s);staticconstexprconst char_type* find(const char_type* s, size_t n, const char_type& a);staticconstexpr char_type* move(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* copy(char_type* s1, const char_type* s2, size_t n);staticconstexpr char_type* assign(char_type* s, size_t n, char_type a);   staticconstexpr int_type not_eof(int_type c)noexcept;staticconstexpr char_type to_char_type(int_type c)noexcept;staticconstexpr int_type to_int_type(char_type c)noexcept;staticconstexprbool eq_int_type(int_type c1, int_type c2)noexcept;staticconstexpr int_type eof()noexcept;};}

[править]Шаблонный класс std::basic_string

namespace std {template<class CharT, class Traits = char_traits<CharT>, class Allocator = allocator<CharT>>class basic_string {public:// типыusing traits_type = Traits;using value_type = CharT;using allocator_type = Allocator;using size_type =typename allocator_traits<Allocator>::size_type;using difference_type =typename allocator_traits<Allocator>::difference_type;using pointer =typename allocator_traits<Allocator>::pointer;using const_pointer =typename allocator_traits<Allocator>::const_pointer;using reference = value_type&;using const_reference =const value_type&;   using iterator =/* определено реализацией */;using const_iterator =/* определено реализацией */;using reverse_iterator =std::reverse_iterator<iterator>;using const_reverse_iterator =std::reverse_iterator<const_iterator>;staticconstexpr size_type npos = size_type(-1);   // создание/копирование/уничтожениеconstexpr basic_string()noexcept(noexcept(Allocator())): basic_string(Allocator()){}constexprexplicit basic_string(const Allocator& a)noexcept;constexpr basic_string(const basic_string& str);constexpr basic_string(basic_string&& str)noexcept;constexpr basic_string(const basic_string& str, size_type pos, const Allocator& a = Allocator());constexpr basic_string(const basic_string& str, size_type pos, size_type n, const Allocator& a = Allocator());constexpr basic_string(basic_string&& str, size_type pos, const Allocator& a = Allocator());constexpr basic_string(basic_string&& str, size_type pos, size_type n, const Allocator& a = Allocator());template<class T>constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());template<class T>constexprexplicit basic_string(const T& t, const Allocator& a = Allocator());constexpr basic_string(const CharT* s, size_type n, const Allocator& a = Allocator());constexpr basic_string(const CharT* s, const Allocator& a = Allocator()); basic_string(nullptr_t)= delete;constexpr basic_string(size_type n, CharT c, const Allocator& a = Allocator());template<class InputIt>constexpr basic_string(InputIt begin, InputIt end, const Allocator& a = Allocator());template<__container_compatible_range<CharT> R>constexpr basic_string(from_range_t, R&& rg, const Allocator& a = Allocator());constexpr basic_string(initializer_list<CharT>, const Allocator&= Allocator());constexpr basic_string(const basic_string&, const Allocator&);constexpr basic_string(basic_string&&, const Allocator&);constexpr ~basic_string();   constexpr basic_string& operator=(const basic_string& str);constexpr basic_string& operator=(basic_string&& str)noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value|| allocator_traits<Allocator>::is_always_equal::value);template<class T>constexpr basic_string& operator=(const T& t);constexpr basic_string& operator=(const CharT* s); basic_string& operator=(nullptr_t)= delete;constexpr basic_string& operator=(CharT c);constexpr basic_string& operator=(initializer_list<CharT>);   // итераторыconstexpr iterator begin()noexcept;constexpr const_iterator begin()constnoexcept;constexpr iterator end()noexcept;constexpr const_iterator end()constnoexcept;   constexpr reverse_iterator rbegin()noexcept;constexpr const_reverse_iterator rbegin()constnoexcept;constexpr reverse_iterator rend()noexcept;constexpr const_reverse_iterator rend()constnoexcept;   constexpr const_iterator cbegin()constnoexcept;constexpr const_iterator cend()constnoexcept;constexpr const_reverse_iterator crbegin()constnoexcept;constexpr const_reverse_iterator crend()constnoexcept;   // ёмкостьconstexpr size_type size()constnoexcept;constexpr size_type length()constnoexcept;constexpr size_type max_size()constnoexcept;constexprvoid resize(size_type n, CharT c);constexprvoid resize(size_type n);template<class Operation>constexprvoid resize_and_overwrite(size_type n, Operation op);constexpr size_type capacity()constnoexcept;constexprvoid reserve(size_type res_arg);constexprvoid shrink_to_fit();constexprvoid clear()noexcept;[[nodiscard]]constexprbool empty()constnoexcept;   // доступ к элементамconstexpr const_reference operator[](size_type pos)const;constexpr reference operator[](size_type pos);constexpr const_reference at(size_type n)const;constexpr reference at(size_type n);   constexprconst CharT& front()const;constexpr CharT& front();constexprconst CharT& back()const;constexpr CharT& back();   // модификаторыconstexpr basic_string& operator+=(const basic_string& str);template<class T>constexpr basic_string& operator+=(const T& t);constexpr basic_string& operator+=(const CharT* s);constexpr basic_string& operator+=(CharT c);constexpr basic_string& operator+=(initializer_list<CharT>);constexpr basic_string& append(const basic_string& str);constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos);template<class T>constexpr basic_string& append(const T& t);template<class T>constexpr basic_string& append(const T& t, size_type pos, size_type n = npos);constexpr basic_string& append(const CharT* s, size_type n);constexpr basic_string& append(const CharT* s);constexpr basic_string& append(size_type n, CharT c);template<class InputIt>constexpr basic_string& append(InputIt first, InputIt last);template<__container_compatible_range<CharT> R>constexpr basic_string& append_range(R&& rg);constexpr basic_string& append(initializer_list<CharT>);   constexprvoid push_back(CharT c);   constexpr basic_string& assign(const basic_string& str);constexpr basic_string& assign(basic_string&& str)noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value|| allocator_traits<Allocator>::is_always_equal::value);constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);template<class T>constexpr basic_string& assign(const T& t);template<class T>constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos);constexpr basic_string& assign(const CharT* s, size_type n);constexpr basic_string& assign(const CharT* s);constexpr basic_string& assign(size_type n, CharT c);template<class InputIt>constexpr basic_string& assign(InputIt first, InputIt last);template<__container_compatible_range<CharT> R>constexpr basic_string& assign_range(R&& rg);constexpr basic_string& assign(initializer_list<CharT>);   constexpr basic_string& insert(size_type pos, const basic_string& str);constexpr basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);template<class T>constexpr basic_string& insert(size_type pos, const T& t);template<class T>constexpr basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos);constexpr basic_string& insert(size_type pos, const CharT* s, size_type n);constexpr basic_string& insert(size_type pos, const CharT* s);constexpr basic_string& insert(size_type pos, size_type n, CharT c);constexpr iterator insert(const_iterator p, CharT c);constexpr iterator insert(const_iterator p, size_type n, CharT c);template<class InputIt>constexpr iterator insert(const_iterator p, InputIt first, InputIt last);template<__container_compatible_range<CharT> R>constexpr iterator insert_range(const_iterator p, R&& rg);constexpr iterator insert(const_iterator p, initializer_list<CharT>);   constexpr basic_string& erase(size_type pos =0, size_type n = npos);constexpr iterator erase(const_iterator p);constexpr iterator erase(const_iterator first, const_iterator last);   constexprvoid pop_back();   constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos);template<class T>constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);template<class T>constexpr basic_string& replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos);constexpr basic_string& replace(size_type pos, size_type n1, const CharT* s, size_type n2);constexpr basic_string& replace(size_type pos, size_type n1, const CharT* s);constexpr basic_string& replace(size_type pos, size_type n1, size_type n2, CharT c);constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);template<class T>constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);constexpr basic_string& replace(const_iterator i1, const_iterator i2, const CharT* s, size_type n);constexpr basic_string& replace(const_iterator i1, const_iterator i2, const CharT* s);constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, CharT c);template<class InputIt>constexpr basic_string& replace(const_iterator i1, const_iterator i2, InputIt j1, InputIt j2);template<__container_compatible_range<CharT> R>constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg);constexpr basic_string& replace(const_iterator, const_iterator, initializer_list<CharT>);   constexpr size_type copy(CharT* s, size_type n, size_type pos =0)const;   constexprvoid swap(basic_string& str)noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value|| allocator_traits<Allocator>::is_always_equal::value);   // строковые операцииconstexprconst CharT* c_str()constnoexcept;constexprconst CharT* data()constnoexcept;constexpr CharT* data()noexcept;constexpr operator basic_string_view<CharT, Traits>()constnoexcept;constexpr allocator_type get_allocator()constnoexcept;   template<class T>constexpr size_type find(const T& t, size_type pos =0)constnoexcept(/* смотрите описание */);constexpr size_type find(const basic_string& str, size_type pos =0)constnoexcept;constexpr size_type find(const CharT* s, size_type pos, size_type n)const;constexpr size_type find(const CharT* s, size_type pos =0)const;constexpr size_type find(CharT c, size_type pos =0)constnoexcept;template<class T>constexpr size_type rfind(const T& t, size_type pos = npos)constnoexcept(/* смотрите описание */);constexpr size_type rfind(const basic_string& str, size_type pos = npos)constnoexcept;constexpr size_type rfind(const CharT* s, size_type pos, size_type n)const;constexpr size_type rfind(const CharT* s, size_type pos = npos)const;constexpr size_type rfind(CharT c, size_type pos = npos)constnoexcept;   template<class T>constexpr size_type find_first_of(const T& t, size_type pos =0)constnoexcept(/* смотрите описание */);constexpr size_type find_first_of(const basic_string& str, size_type pos =0)constnoexcept;constexpr size_type find_first_of(const CharT* s, size_type pos, size_type n)const;constexpr size_type find_first_of(const CharT* s, size_type pos =0)const;constexpr size_type find_first_of(CharT c, size_type pos =0)constnoexcept;template<class T>constexpr size_type find_last_of(const T& t, size_type pos = npos)constnoexcept(/* смотрите описание */);constexpr size_type find_last_of(const basic_string& str, size_type pos = npos)constnoexcept;constexpr size_type find_last_of(const CharT* s, size_type pos, size_type n)const;constexpr size_type find_last_of(const CharT* s, size_type pos = npos)const;constexpr size_type find_last_of(CharT c, size_type pos = npos)constnoexcept;   template<class T>constexpr size_type find_first_not_of(const T& t, size_type pos =0)constnoexcept(/* смотрите описание */);constexpr size_type find_first_not_of(const basic_string& str, size_type pos =0)constnoexcept;constexpr size_type find_first_not_of(const CharT* s, size_type pos, size_type n)const;constexpr size_type find_first_not_of(const CharT* s, size_type pos =0)const;constexpr size_type find_first_not_of(CharT c, size_type pos =0)constnoexcept;template<class T>constexpr size_type find_last_not_of(const T& t, size_type pos = npos)constnoexcept(/* смотрите описание */);constexpr size_type find_last_not_of(const basic_string& str, size_type pos = npos)constnoexcept;constexpr size_type find_last_not_of(const CharT* s, size_type pos, size_type n)const;constexpr size_type find_last_not_of(const CharT* s, size_type pos = npos)const;constexpr size_type find_last_not_of(CharT c, size_type pos = npos)constnoexcept;   constexpr basic_string substr(size_type pos =0, size_type n = npos)const&;constexpr basic_string substr(size_type pos =0, size_type n = npos)&&;   template<class T>constexprint compare(const T& t)constnoexcept(/* смотрите описание */);template<class T>constexprint compare(size_type pos1, size_type n1, const T& t)const;template<class T>constexprint compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos)const;constexprint compare(const basic_string& str)constnoexcept;constexprint compare(size_type pos1, size_type n1, const basic_string& str)const;constexprint compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos)const;constexprint compare(const CharT* s)const;constexprint compare(size_type pos1, size_type n1, const CharT* s)const;constexprint compare(size_type pos1, size_type n1, const CharT* s, size_type n2)const;   constexprbool starts_with(basic_string_view<CharT, Traits> x)constnoexcept;constexprbool starts_with(CharT x)constnoexcept;constexprbool starts_with(const CharT* x)const;constexprbool ends_with(basic_string_view<CharT, Traits> x)constnoexcept;constexprbool ends_with(CharT x)constnoexcept;constexprbool ends_with(const CharT* x)const;   constexprbool contains(basic_string_view<CharT, Traits> x)constnoexcept;constexprbool contains(CharT x)constnoexcept;constexprbool contains(const CharT* x)const;};   template<class InputIt, class Allocator = allocator<typename iterator_traits<InputIt>::value_type>> basic_string(InputIt, InputIt, Allocator = Allocator())-> basic_string<typename iterator_traits<InputIt>::value_type, char_traits<typename iterator_traits<InputIt>::value_type>, Allocator>;   template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>> basic_string(from_range_t, R&&, Allocator = Allocator())-> basic_string<ranges::range_value_t<R>, char_traits<ranges::range_value_t<R>>, Allocator>;   template<class CharT, class Traits, class Allocator = allocator<CharT>>explicit basic_string(basic_string_view<CharT, Traits>, const Allocator&= Allocator())-> basic_string<CharT, Traits, Allocator>;   template<class CharT, class Traits, class Allocator = allocator<CharT>> basic_string(basic_string_view<CharT, Traits>, typename/* смотрите описание */::size_type, typename/* смотрите описание */::size_type, const Allocator&= Allocator())-> basic_string<CharT, Traits, Allocator>;}

[править]Отчёты о дефектах

Следующие изменения поведения были применены с обратной силой к ранее опубликованным стандартам C++:

Номер Применён Поведение в стандарте Корректное поведение
LWG 209 C++98 объявления следующих элементов std::basic_string использовали
противоречивые стили в резюме:
  • void push_back(CharT c);
  • basic_string& assign(const basic_string& str);
  • void swap(basic_string& str);
унифицировали стили
close