C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- æ ååºå¤´æä»¶ <ctime>
- æ ååºå¤´æä»¶ <cstring>
- æ ååºå¤´æä»¶ <set>
- æ ååºå¤´æä»¶ <cctype>
- æ ååºå¤´æä»¶ <cwctype>
- æ ååºå¤´æä»¶ <utility>
- æ ååºå¤´æä»¶ <queue>
- æ ååºå¤´æä»¶ <complex>
- æ ååºå¤´æä»¶ <iterator>
- æ ååºå¤´æä»¶ <algorithm>
- æ ååºå¤´æä»¶ <valarray>
- æ ååºå¤´æä»¶ <numeric>
- æ ååºå¤´æä»¶ <cmath>
- æ ååºå¤´æä»¶ <iosfwd>
- æ ååºå¤´æä»¶ <ios>
- æ ååºå¤´æä»¶ <iomanip>
- æ ååºå¤´æä»¶ <streambuf>
- æ ååºå¤´æä»¶ <istream>
- æ ååºå¤´æä»¶ <ostream>
- æ ååºå¤´æä»¶ <iostream>
- æ ååºå¤´æä»¶ <sstream>
- æ ååºå¤´æä»¶ <clocale>
- æ ååºå¤´æä»¶ <vector>
- æ ååºå¤´æä»¶ <deque>
- æ ååºå¤´æä»¶ <list>
- æ ååºå¤´æä»¶ <map>
- æ ååºå¤´æä»¶ <cwchar>
- æ ååºå¤´æä»¶ <locale>
- æ ååºå¤´æä»¶ <codecvt>
- æ ååºå¤´æä»¶ <bitset>
- æ ååºå¤´æä»¶ <functional>
- æ ååºå¤´æä»¶ <stdexcept>
- æ ååºå¤´æä»¶ <csignal>
- æ ååºå¤´æä»¶ <csetjmp>
- æ ååºå¤´æä»¶ <stack>
- æ ååºå¤´æä»¶ <cassert>
- æ ååºå¤´æä»¶ <cerrno>
- æ ååºå¤´æä»¶ <memory>
- æ ååºå¤´æä»¶ <typeindex>
- æ ååºå¤´æä»¶ <type_traits>
- æ ååºå¤´æä»¶ <chrono>
- æ ååºå¤´æä»¶ <initializer_list>
- æ ååºå¤´æä»¶ <tuple>
- æ ååºå¤´æä»¶ <scoped_allocator>
- æ ååºå¤´æä»¶ <cstdint>
- æ ååºå¤´æä»¶ <cinttypes>
- æ ååºå¤´æä»¶ <system_error>
- æ ååºå¤´æä»¶ <cuchar>
- æ ååºå¤´æä»¶ <array>
- æ ååºå¤´æä»¶ <forward_list>
- æ ååºå¤´æä»¶ <unordered_set>
- æ ååºå¤´æä»¶ <unordered_map>
- æ ååºå¤´æä»¶ <random>
- æ ååºå¤´æä»¶ <ratio>
- æ ååºå¤´æä»¶ <cfenv>
- æ ååºå¤´æä»¶ <regex>
- æ ååºå¤´æä»¶ <atomic>
- æ ååºå¤´æä»¶ <thread>
- æ ååºå¤´æä»¶ <mutex>
- æ ååºå¤´æä»¶ <future>
- æ ååºå¤´æä»¶ <condition_variable>
- æ ååºå¤´æä»¶ <any>
- æ ååºå¤´æä»¶ <optional>
- æ ååºå¤´æä»¶ <variant>
- æ ååºå¤´æä»¶ <memory_resource>
- æ ååºå¤´æä»¶ <string_view>
- æ ååºå¤´æä»¶ <charconv>
- æ ååºå¤´æä»¶ <execution>
- æ ååºå¤´æä»¶ <filesystem>
- æ ååºå¤´æä»¶ <concepts>
- æ ååºå¤´æä»¶ <coroutine>
- æ ååºå¤´æä»¶ <compare>
- æ ååºå¤´æä»¶ <version>
- æ ååºå¤´æä»¶ <source_location>
- æ ååºå¤´æä»¶ <format>
- æ ååºå¤´æä»¶ <span>
- æ ååºå¤´æä»¶ <ranges>
- æ ååºå¤´æä»¶ <bit>
- æ ååºå¤´æä»¶ <numbers>
- æ ååºå¤´æä»¶ <syncstream>
- æ ååºå¤´æä»¶ <stop_token>
- æ ååºå¤´æä»¶ <semaphore>
- æ ååºå¤´æä»¶ <latch>
- æ ååºå¤´æä»¶ <barrier>
- æ ååºå¤´æä»¶ <string>
- æ ååºå¤´æä»¶ <cstddef>
- æ ååºå¤´æä»¶ <limits>
- æ ååºå¤´æä»¶ <cfloat>
- æ ååºå¤´æä»¶ <climits>
- æ ååºå¤´æä»¶ <cstdlib>
- æ ååºå¤´æä»¶ <new>
- æ ååºå¤´æä»¶ <typeinfo>
- æ ååºå¤´æä»¶ <exception>
- æ ååºå¤´æä»¶ <cstdarg>
- æ ååºå¤´æä»¶ <ciso646>
- æ ååºå¤´æä»¶ <cstdalign>
- æ ååºå¤´æä»¶ <cstdbool>
- æ ååºå¤´æä»¶ <fstream>
- æ ååºå¤´æä»¶ <cstdio>
- æ ååºå¤´æä»¶ <strstream>
- æ ååºå¤´æä»¶ <shared_mutex>
- æ ååºå¤´æä»¶ <ccomplex>
- æ ååºå¤´æä»¶ <ctgmath>
- 注é
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >C++ æ ååºå¤´æä»¶ > æ ååºå¤´æä»¶ <string>
æ ååºå¤´æä»¶ <string>
æ¤å¤´æä»¶æ¯å符串åºçä¸é¨åã
å å«
| <initializer_list> | (C++11 èµ·) |
| <compare> | (C++20 èµ·) |
ç±»
| Â | |
| åç§° | æè¿° |
| std::char_traits | æè¿°å符类åçæ§è´¨ç类模æ¿(类模æ¿) |
| 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::basic_string | è¡¨ç¤ºææ¬å符串对象ç类模æ¿(类模æ¿) |
| std::string | std::basic_string<char> (typedef) |
| std::u8string (C++20) | std::basic_string<char8_t> (typedef) |
| std::u16string (C++11) | std::basic_string<char16_t> (typedef) |
| std::u32string (C++11) | std::basic_string<char32_t> (typedef) |
| std::wstring | std::basic_string<wchar_t> (typedef) |
| std::pmr::basic_string (C++17) | (å«å模æ¿) |
| std::pmr::string (C++17) | std::pmr::basic_string<char> (typedef) |
| std::pmr::u8string (C++20) | std::pmr::basic_string<char8_t> (typedef) |
| std::pmr::u16string (C++17) | std::pmr::basic_string<char16_t> (typedef) |
| std::pmr::u32string (C++17) | std::pmr::basic_string<char32_t> (typedef) |
| std::pmr::wstring (C++17) | std::pmr::basic_string<wchar_t> (typedef) |
| std::hash<std::string> (C++11) | (类模æ¿ç¹å) |
| std::hash<std::u8string> (C++20) | (类模æ¿ç¹å) |
| std::hash<std::u16string> (C++11) | (类模æ¿ç¹å) |
| std::hash<std::u32string> (C++11) | (类模æ¿ç¹å) |
| std::hash<std::wstring> (C++11) | (类模æ¿ç¹å) |
| std::hash<std::pmr::string> (C++20) | (类模æ¿ç¹å) |
| std::hash<std::pmr::u8string> (C++20) | (类模æ¿ç¹å) |
| std::hash<std::pmr::u16string> (C++20) | (类模æ¿ç¹å) |
| std::hash<std::pmr::u32string> (C++20) | (类模æ¿ç¹å) |
| std::hash<std::pmr::wstring> (C++20) | (类模æ¿ç¹å) |
彿°
| è¿æ¥ä¸¤ä¸ªå符串æè
ä¸ä¸ªå符串åä¸ä¸ªå符 (彿°æ¨¡æ¿) | |
| (C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20) |
以åå
¸åºæ¯è¾ä¸¤ä¸ªå符串 (彿°æ¨¡æ¿) |
| ç¹å std::swap ç®æ³ (彿°æ¨¡æ¿) | |
è¾å ¥/è¾åº | |
| æ§è¡åç¬¦ä¸²çæµè¾å
¥ä¸è¾åº (彿°æ¨¡æ¿) | |
| ä» I/O æµè¯»åæ°æ®å°å符串 (彿°æ¨¡æ¿) | |
æ°å¼è½¬æ¢ | |
| (C++11)(C++11)(C++11) |
转æ¢å符串为æç¬¦å·æ´æ° (彿°) |
| (C++11)(C++11) |
转æ¢å符串为æ ç¬¦å·æ´æ° (彿°) |
| (C++11)(C++11)(C++11) |
转æ¢å符串为浮ç¹å¼ (彿°) |
| (C++11) |
è½¬æ¢æ´æ°ææµ®ç¹å¼ä¸º string (彿°) |
| (C++11) |
è½¬æ¢æ´æ°ææµ®ç¹å¼ä¸º wstring (彿°) |
åé¢é
| å®ä¹äºå
èå½å空é´
std::literals::string_literals | |
| (C++14) |
转æ¢å符æ°ç»åé¢é为 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_string template<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 bool operator==(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 /* è§å®ä¹ */ 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> constexpr void 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> 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 Pred> constexpr typename basic_string<CharT, Traits, Allocator>::size_type erase_if(basic_string<CharT, Traits, Allocator>& c, Pred pred);  // basic_string typedef å 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>;  // æ°å¼è½¬æ¢ int 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>; }  // æ£åæ¯æ template<class T> struct hash; template<> struct hash<string>; template<> struct hash<u8string>; template<> struct hash<u16string>; template<> struct hash<u32string>; template<> struct hash<wstring>; template<> struct hash<pmr::string>; template<> struct hash<pmr::u8string>; template<> struct hash<pmr::u16string>; template<> struct hash<pmr::u32string>; template<> struct hash<pmr::wstring>;  inline namespace literals { inline namespace string_literals { // basic_string åé¢éåç¼ constexpr 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); } } }
ç±»æ¨¡æ¿ 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; Â static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; Â static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); Â static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr int_type eof() noexcept; }; Â template<> struct char_traits<char8_t> { using char_type = char8_t; using int_type = unsigned int; using off_type = streamoff; using pos_type = u8streampos; using state_type = mbstate_t; using comparison_category = strong_ordering; Â static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; Â static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr 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; Â static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; Â static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); Â static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr 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; Â static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; Â static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); Â static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr 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; Â static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; Â static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); Â static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr 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>; static const size_type npos = -1;  // æé /å¤å¶/鿝 constexpr basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { } constexpr explicit 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()); template<class T> constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); template<class T> constexpr explicit 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()); 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()); 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); constexpr basic_string& operator=(CharT c); constexpr basic_string& operator=(initializer_list<CharT>);  // è¿ä»£å¨ constexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept;  constexpr reverse_iterator rbegin() noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr reverse_iterator rend() noexcept; constexpr const_reverse_iterator rend() const noexcept;  constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept;  // 容é constexpr size_type size() const noexcept; constexpr size_type length() const noexcept; constexpr size_type max_size() const noexcept; constexpr void resize(size_type n, CharT c); constexpr void resize(size_type n); constexpr size_type capacity() const noexcept; constexpr void reserve(size_type res_arg); void reserve(); // å¼ç¨ constexpr void shrink_to_fit(); constexpr void clear() noexcept; [[nodiscard]] constexpr bool empty() const noexcept;  // å ç´ è®¿é® 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);  constexpr const CharT& front() const; constexpr CharT& front(); constexpr const 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); constexpr basic_string& append(initializer_list<CharT>);  constexpr void 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); 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); 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);  constexpr void 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); 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;  constexpr void swap(basic_string& str) noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value || allocator_traits<Allocator>::is_always_equal::value);  // å符串æä½ constexpr const CharT* c_str() const noexcept; constexpr const CharT* data() const noexcept; constexpr CharT* data() noexcept; constexpr operator basic_string_view<CharT, Traits>() const noexcept; constexpr allocator_type get_allocator() const noexcept;  template<class T> constexpr size_type find(const T& t, size_type pos = 0) const noexcept(/* è§å®ä¹ */); constexpr size_type find(const basic_string& str, size_type pos = 0) const noexcept; 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) const noexcept; template<class T> constexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(/* è§å®ä¹ */); constexpr size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; 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) const noexcept;  template<class T> constexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(/* è§å®ä¹ */); constexpr size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; 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) const noexcept; template<class T> constexpr size_type find_last_of(const T& t, size_type pos = npos) const noexcept(/* è§å®ä¹ */); constexpr size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; 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) const noexcept;  template<class T> constexpr size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept(/* è§å®ä¹ */); constexpr size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; 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) const noexcept; template<class T> constexpr size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept(/* è§å®ä¹ */); constexpr size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; 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) const noexcept;  constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;  template<class T> constexpr int compare(const T& t) const noexcept(/* è§å®ä¹ */); template<class T> constexpr int compare(size_type pos1, size_type n1, const T& t) const; template<class T> constexpr int compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos) const; constexpr int compare(const basic_string& str) const noexcept; constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const; constexpr int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const; constexpr int compare(const CharT* s) const; constexpr int compare(size_type pos1, size_type n1, const CharT* s) const; constexpr int compare(size_type pos1, size_type n1, const CharT* s, size_type n2) const;  constexpr bool starts_with(basic_string_view<CharT, Traits> x) const noexcept; constexpr bool starts_with(CharT x) const noexcept; constexpr bool starts_with(const CharT* x) const; constexpr bool ends_with(basic_string_view<CharT, Traits> x) const noexcept; constexpr bool ends_with(CharT x) const noexcept; constexpr bool ends_with(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<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>; }