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>::ends_with
std::basic_string<CharT,Traits,Allocator>::ends_with
| constexpr bool ends_with( std::basic_string_view<CharT,Traits> sv ) Â Â const noexcept; |
(1) | (C++20 èµ·) |
| constexpr bool ends_with( CharT c ) const noexcept; |
(2) | (C++20 èµ·) |
| constexpr bool ends_with( const CharT* s ) const; |
(3) | (C++20 èµ·) |
æ£æ¥ string æ¯å¦ç»äºç»å®åç¼ãåç¼å¯ä¸ºä»¥ä¸ä¹ä¸ï¼
1) string_view
sv ï¼å¯ä»¥æ¯ä»å¦ä¸ std::basic_string éå¼è½¬æ¢çç»æï¼ã2) å个å符
c3) ç©ºç»æ¢å符串
sææä¸ä¸ªéè½½çæå°è¿å std::basic_string_view<CharT, Traits>(data(), size()).ends_with(x) ï¼å
¶ä¸ x æ¯åæ°ã
åæ°
| sv | - | string_view ï¼å¯ä¸ºä»å¦ä¸ std::basic_string éå¼è½¬æ¢çç»æ
|
| c | - | å个å符 |
| s | - | ç©ºç»æ¢å符串 |
è¿åå¼
è¥ string ç»äºç»å®åç¼å为 true ï¼å¦å为 false ã
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <string_view> #include <string> Â template <typename SuffixType> void test_suffix_print(const std::string& str, SuffixType suffix) { std::cout << '\'' << str << "' ends with '" << suffix << "': " << str.ends_with(suffix) << '\n'; } Â int main() { std::boolalpha(std::cout); auto helloWorld = std::string("hello world"); Â test_suffix_print(helloWorld, std::string_view("world")); Â test_suffix_print(helloWorld, std::string_view("goodby")); Â test_suffix_print(helloWorld, 'd'); Â test_suffix_print(helloWorld, 'x'); }
è¾åºï¼
'hello world' ends with 'world': true 'hello world' ends with 'goodby': false 'hello world' ends with 'd': true 'hello world' ends with 'x': false
åé
| (C++20) |
æ£æ¥ string æ¯å¦å§äºç»å®åç¼ (å ¬å¼æå彿°) |
| (C++20) |
æ£æ¥ string_view æ¯å¦å§äºç»å®åç¼ ( std::basic_string_view<CharT,Traits> çå
¬å¼æå彿°) |
| (C++20) |
æ£æ¥ string_view æ¯å¦ç»äºç»å®åç¼ ( std::basic_string_view<CharT,Traits> çå
¬å¼æå彿°) |
| æ¯è¾äºä¸ªå符串 (å ¬å¼æå彿°) | |
| è¿åå串 (å ¬å¼æå彿°) |