C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- std::basic_string
- std::basic_string<CharT,Traits,Allocator>::npos
- std::basic_string<CharT,Traits,Allocator>::at
- std::hash (std::string, std::wstring, std::u16string, std::u32string, std::pmr::string, std::pmr::wstring, std::pmr::u16string, std::pmr::u32string)
- std::basic_string<CharT,Traits,Allocator>::assign
- std::basic_string<CharT,Traits,Allocator>::get_allocator
- std::basic_string<CharT,Traits,Allocator>::substr
- std::basic_string<CharT,Traits,Allocator>::basic_string
- std::basic_string<CharT,Traits,Allocator>::operator=
- std::basic_string<CharT,Traits,Allocator>::operator[]
- std::basic_string<CharT,Traits,Allocator>::front
- std::basic_string<CharT,Traits,Allocator>::back
- std::basic_string<CharT,Traits,Allocator>::data
- std::basic_string<CharT,Traits,Allocator>::c_str
- std::basic_string<CharT,Traits,Allocator>::operator basic_string_view
- std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin
- std::basic_string<CharT,Traits,Allocator>::end, std::basic_string<CharT,Traits,Allocator>::cend
- std::basic_string<CharT,Traits,Allocator>::rbegin, std::basic_string<CharT,Traits,Allocator>::crbegin
- std::basic_string<CharT,Traits,Allocator>::rend, std::basic_string<CharT,Traits,Allocator>::crend
- std::basic_string<CharT,Traits,Allocator>::empty
- std::basic_string<CharT,Traits,Allocator>::size, std::basic_string<CharT,Traits,Allocator>::length
- std::basic_string<CharT,Traits,Allocator>::max_size
- std::basic_string<CharT,Traits,Allocator>::reserve
- std::basic_string<CharT,Traits,Allocator>::capacity
- std::basic_string<CharT,Traits,Allocator>::shrink_to_fit
- std::basic_string<CharT,Traits,Allocator>::clear
- std::basic_string<CharT,Traits,Allocator>::insert
- std::basic_string<CharT,Traits,Allocator>::erase
- std::basic_string<CharT,Traits,Allocator>::push_back
- std::basic_string<CharT,Traits,Allocator>::pop_back
- std::basic_string<CharT,Traits,Allocator>::append
- std::basic_string<CharT,Traits,Allocator>::operator+=
- std::basic_string<CharT,Traits,Allocator>::compare
- std::basic_string<CharT,Traits,Allocator>::starts_with
- std::basic_string<CharT,Traits,Allocator>::ends_with
- std::basic_string<CharT,Traits,Allocator>::replace
- std::basic_string<CharT,Traits,Allocator>::copy
- std::basic_string<CharT,Traits,Allocator>::resize
- std::basic_string<CharT,Traits,Allocator>::swap
- std::basic_string<CharT,Traits,Allocator>::find
- std::basic_string<CharT,Traits,Allocator>::rfind
- std::basic_string<CharT,Traits,Allocator>::find_first_of
- std::basic_string<CharT,Traits,Allocator>::find_first_not_of
- std::basic_string<CharT,Traits,Allocator>::find_last_of
- std::basic_string<CharT,Traits,Allocator>::find_last_not_of
- std::operator+(std::basic_string)
- std::swap(std::basic_string)
- std::literals::string_literals::operator""s
- std::erase, std::erase_if (std::basic_string)
- operator<<,>>(std::basic_string)
- std::getline
- operator==,!=,<,<=,>,>=,<=>(std::basic_string)
- std::stoi, std::stol, std::stoll
- std::stoul, std::stoull
- std::stof, std::stod, std::stold
- std::to_string
- std::to_wstring
- std::basic_string çæ¨å¯¼æå¼
- std::basic_string_view
- ç©ºç»æ¢åèå符串
- ç©ºç»æ¢å¤åèå符串
- ç©ºç»æ¢å®½å符串
- std::char_traits
- 注é
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >åç¬¦ä¸²åº >std::basic_string > std::basic_string çæ¨å¯¼æå¼
std::basic_string çæ¨å¯¼æå¼
| å®ä¹äºå¤´æä»¶ <string>
|
||
| template<class InputIt, class Alloc = std::allocator< Â Â Â Â Â Â Â Â Â Â Â Â Â typename std::iterator_traits<InputIt>::value_type>> |
(C++17 èµ·) | |
| å®ä¹äºå¤´æä»¶ <string>
|
||
| template<class InputIt, class Alloc = std::allocator< Â Â Â Â Â Â Â Â Â Â Â Â Â typename std::iterator_traits<InputIt>::value_type>> |
(1) | (C++17 èµ·) |
| template<class CharT, Â Â Â Â Â class Traits, |
(2) | (C++17 èµ·) |
| template<class CharT, Â Â Â Â Â class Traits, |
(3) | (C++17 èµ·) |
InputIt 满足éçè¾å
¥è¿ä»£å¨ (LegacyInputIterator) ä¸ Alloc 满足åé
å¨ (Allocator) æåä¸éè½½å³è®®ãAlloc 满足åé
å¨ (Allocator) æåä¸éè½½å³è®®ã注æï¼åºç¡®å®ç±»åæ¯å¦æ»¡è¶³éçè¾å
¥è¿ä»£å¨ (LegacyInputIterator) çç¨åº¦æ¯æªæå®çï¼é¤äºæä½è¦æ±æ¯æ´æ°ç±»åä¸å
·å¤è¾å
¥è¿ä»£å¨çæ¡ä»¶ã类似å°ï¼ç¡®å®ç±»åæ¯å¦æ»¡è¶³åé
å¨ (Allocator) æ¯æªæå®çï¼é¤äºæä½è¦æ±æ¯æåç±»å Alloc::value_type å¿
é¡»åå¨ï¼ä¸è¡¨è¾¾å¼ std::declval<Alloc&>().allocate(std::size_t{}) å¨ä½ä¸ºä¸æ±å¼æä½æ°æ¶å¿
é¡»ä¸ºè¯æã
注æ
éè¦æå¼ (2-3) ï¼å 为 std::basic_string å¯¹äº std::basic_string_view çæé 彿°è¢«è®¾ä¸ºæ¨¡æ¿ï¼ä»¥é¿å æ¢å代ç ä¸çæ§ä¹ï¼èè¿äºæ¨¡æ¿ä¸æ¯æç±»æ¨¡æ¿å®åæ¨å¯¼ã
ç¼ºé·æ¥å
ä¸åæ´æ¹è¡ä¸ºçç¼ºé·æ¥å追溯å°åºç¨äºä»¥ååºçç C++ æ åã
| DR | åºç¨äº | åºçæ¶çè¡ä¸º | æ£ç¡®è¡ä¸º |
|---|---|---|---|
| LWG 3075 | C++17 | 䏿¯æä» basic_string_view æ¨å¯¼ï¼ä¸º LWG é®é¢ 2946 ææ¶åï¼
|
æ·»å æ¨å¯¼æå¼ |
示ä¾
#include <string> #include <vector> int main() { std::vector<char> v = {'a', 'b', 'c'}; std::basic_string s(v.begin(), v.end()); // ä½¿ç¨æ¾å¼æ¨å¯¼æå¼ }