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_view>
æ ååºå¤´æä»¶ <string_view>
æ¤å¤´æä»¶æ¯å符串åºçä¸é¨åã
ç±»
| (C++17) |
åªè¯»çå符串è§å¾ (类模æ¿) |
| std::string_view | std::basic_string_view<char> |
| std::u8string_view | std::basic_string_view<char8_t> (C++20) |
| std::u16string_view | std::basic_string_view<char16_t> |
| std::u32string_view | std::basic_string_view<char32_t> |
| std::wstring_view | std::basic_string_view<wchar_t> |
| string_view çæ£åæ¯æ (类模æ¿ç¹å) |
彿°
| (C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20 ä¸ç§»é¤)(C++20) |
以åå
¸åºæ¯è¾ä¸¤ä¸ªå符串è§å¾ (彿°æ¨¡æ¿) |
| è¿è¡å符串è§å¾çæµè¾åº (彿°æ¨¡æ¿) |
æ¦è¦
namespace std {  // ç±»æ¨¡æ¿ basic_string_view template<class charT, class traits = char_traits<charT>> class basic_string_view;  // éæåæ¯è¾å½æ° template<class charT, class traits> constexpr bool operator==(basic_string_view<charT, traits> x, basic_string_view<charT, traits> y) noexcept; template<class charT, class traits> constexpr bool operator!=(basic_string_view<charT, traits> x, basic_string_view<charT, traits> y) noexcept; template<class charT, class traits> constexpr bool operator< (basic_string_view<charT, traits> x, basic_string_view<charT, traits> y) noexcept; template<class charT, class traits> constexpr bool operator> (basic_string_view<charT, traits> x, basic_string_view<charT, traits> y) noexcept; template<class charT, class traits> constexpr bool operator<=(basic_string_view<charT, traits> x, basic_string_view<charT, traits> y) noexcept; template<class charT, class traits> constexpr bool operator>=(basic_string_view<charT, traits> x, basic_string_view<charT, traits> y) noexcept; /* å è¶³çæ¯è¾å½æ°çé¢å¤éè½½ */  // æå ¥ç¬¦ä¸æå符 template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, basic_string_view<charT, traits> str);  // basic_string_view typedef å using string_view = basic_string_view<char>; using u8string_view = basic_string_view<char8_t>; using u16string_view = basic_string_view<char16_t>; using u32string_view = basic_string_view<char32_t>; using wstring_view = basic_string_view<wchar_t>;  // æ£åæ¯æ template<class T> struct hash; template<> struct hash<string_view>; template<> struct hash<u8string_view>; template<> struct hash<u16string_view>; template<> struct hash<u32string_view>; template<> struct hash<wstring_view>;  inline namespace literals { inline namespace string_view_literals { // basic_string_view åé¢éçåç¼ constexpr string_view operator "" sv(const char* str, size_t len) noexcept; constexpr u8string_view operator "" sv(const char16_t* str, size_t len) noexcept; constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept; constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept; constexpr wstring_view operator "" sv(const wchar_t* str, size_t len) noexcept; } } } // namespace std
ç±»æ¨¡æ¿ std::basic_string_view
template<class charT, class traits = char_traits<charT>> class basic_string_view { public: // ç±»å typedef traits traits_type; typedef charT value_type; typedef charT* pointer; typedef const charT* const_pointer; typedef charT& reference; typedef const charT& const_reference; typedef /* ç±å®ç°å®ä¹ */ const_iterator; typedef const_iterator iterator; typedef reverse_iterator<const_iterator> const_reverse_iterator; typedef const_reverse_iterator reverse_iterator; typedef size_t size_type; typedef ptrdiff_t difference_type; static constexpr size_type npos = size_type(-1);  // æé ä¸èµå¼ constexpr basic_string_view() noexcept; constexpr basic_string_view(const basic_string_view&) noexcept = default; basic_string_view &operator=(const basic_string_view&) noexcept = default; constexpr basic_string_view(const charT* str); constexpr basic_string_view(const charT* str, size_type len);  // è¿ä»£å¨æ¯æ constexpr const_iterator begin() const noexcept; constexpr const_iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr const_reverse_iterator rend() 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; [[nodiscard]] constexpr bool empty() const noexcept;  // å ç´ è®¿é® constexpr const_reference operator[](size_type pos) const; constexpr const_reference at(size_type pos) const; constexpr const_reference front() const; constexpr const_reference back() const; constexpr const_pointer data() const noexcept;  // ä¿®æ¹å¨ constexpr void remove_prefix(size_type n); constexpr void remove_suffix(size_type n); constexpr void swap(basic_string_view& s) noexcept;  // å符串æä½ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const; constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; constexpr int compare(basic_string_view s) const noexcept; constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; constexpr int compare(size_type pos1, size_type n1, basic_string_view s, size_type pos2, size_type n2) 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 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 x) const noexcept; constexpr bool ends_with(charT x) const noexcept; constexpr bool ends_with(const charT* x) const; constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find(charT c, 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 rfind(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type rfind(charT c, 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 find_first_of(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find_first_of(charT c, 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_last_of(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type find_last_of(charT c, 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_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find_first_not_of(charT c, 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_last_not_of(basic_string_view s,size_type pos = npos) const noexcept; constexpr size_type find_last_not_of(charT c, 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; private: const_pointer data_; // ä» ç¨äºéé size_type size_; // ä» ç¨äºéé };  }