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<CharT,Traits,Allocator>::erase
std::basic_string<CharT,Traits,Allocator>::erase
| (1) | ||
| basic_string& erase( size_type index = 0, size_type count = npos ); |
(C++20 å) | |
| constexpr basic_string& erase( size_type index = 0, size_type count = npos ); |
(C++20 èµ·) | |
| (2) | ||
| iterator erase( iterator position ); |
(C++11 å) | |
| iterator erase( const_iterator position ); |
(C++11 èµ·) (C++20 å) |
|
| constexpr iterator erase( const_iterator position ); |
(C++20 èµ·) | |
| (3) | ||
| iterator erase( iterator first, iterator last ); |
(C++11 å) | |
| iterator erase( const_iterator first, const_iterator last ); |
(C++11 èµ·) (C++20 å) |
|
| constexpr iterator erase( const_iterator first, const_iterator last ); |
(C++20 èµ·) | |
ä» string ç§»é¤æå®çå符ã
2) ç§»é¤ä½äº
position çå符ã3) ç§»é¤èå´
[first, last) ä¸çå符ãåæ°
| index | - | è¦ç§»é¤çé¦ä¸ªå符 |
| count | - | è¦ç§»é¤çåç¬¦æ° |
| position | - | æåè¦ç§»é¤çå符çè¿ä»£å¨ |
| first, last | - | è¦ç§»é¤çå符èå´ |
è¿åå¼
1) *this
2) æåç«å³åé被æ¦é¤å符çè¿ä»£å¨ï¼æè¥ä¸åå¨è¿ç§å符å为
end()3) æåæ¦é¤å
last ææåå符çè¿ä»£å¨ï¼æè¥ä¸åå¨è¿ç§å符å为 end()å¼å¸¸
2-3) ï¼æ ï¼
任使 åµä¸ï¼è¥å ä»»ä½åå æåºå¼å¸¸ï¼åæ¤å½æ°æ ææï¼å¼ºå¼å¸¸ä¿è¯ï¼ã (C++11 èµ·)
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <algorithm> #include <string>  int main() { std::string s = "This is an example"; std::cout << s << '\n';  s.erase(0, 5); // æ¦é¤ "This " std::cout << s << '\n';  s.erase(std::find(s.begin(), s.end(), ' ')); // æ¦é¤ ' ' std::cout << s << '\n';  s.erase(s.find(' ')); // ä» ' ' å°å符串尾è£åª std::cout << s << '\n'; }
è¾åºï¼
This is an example is an example isan example isan
åé
| æ¸
é¤å
容 (å ¬å¼æå彿°) |