std::basic_string<CharT,Traits,Allocator>::rfind
cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (1) | ||
size_type rfind( const basic_string& str, size_type pos = npos ) const; |
( C++11) | |
size_type rfind( const basic_string& str, size_type pos = npos ) const noexcept; |
( C++11) ( C++20) |
|
constexpr size_type rfind( const basic_string& str, size_type pos = npos ) const noexcept; |
( C++20) | |
| (2) | ||
size_type rfind( const CharT* s, size_type pos, size_type count ) const; |
( C++20) | |
constexpr size_type rfind( const CharT* s, size_type pos, size_type count ) const; |
( C++20) | |
| (3) | ||
size_type rfind( const CharT* s, size_type pos = npos ) const; |
( C++20) | |
constexpr size_type rfind( const CharT* s, size_type pos = npos ) const; |
( C++20) | |
| (4) | ||
size_type rfind( CharT ch, size_type pos = npos ) const; |
( C++11) | |
size_type rfind( CharT ch, size_type pos = npos ) const noexcept; |
( C++11) ( C++20) |
|
constexpr size_type rfind( CharT ch, size_type pos = npos ) const noexcept; |
( C++20) | |
| (5) | ||
template< class StringViewLike > size_type rfind( const StringViewLike& t, size_type pos = npos ) const noexcept(/* */); |
( C++17) ( C++20) |
|
template< class StringViewLike > constexpr size_type rfind( const StringViewLike& t, size_type pos = npos ) const noexcept(/* */); |
( C++20) | |
, . pos ( , , , , pos). npos size()- 1 pos, .
1) ,
str.2) ,
[s, s + count). .3) , ,
s. Traits::length(s).4) ,
ch.5)
t sv, std::basic_string_view<CharT, Traits> sv = t;, , sv. ,
std::is_convertible_v<const StringViewLike&,std::basic_string_view<CharT, Traits>> true std::is_convertible_v<const StringViewLike&, const CharT*> false.
| str | ||
| pos | , | |
| count | ||
| s | ||
| ch | ||
| t | ( std::basic_string_view) |
npos, . , , .
(.. str.size(), count Traits::length(s) ), , rfind :
pos,pos < size();size(), ,pos == npos.
1,4) .
5)
noexcept:
noexcept(std::is_nothrow_convertible_v<const T&, std::basic_string_view<CharT, Traits>>)#include <iomanip>
#include <iostream>
#include <string>
void print(std::string::size_type n,
std::string::size_type len,
std::string const &s)
{
if (n == std::string::npos)
std::cout << " \n";
else
std::cout << ": " << std::quoted(s.substr(n, len)) << " " << n << '\n';
}
int main()
{
std::string::size_type n;
std::string const s = "This is a string";
//
n = s.rfind("is");
print(n, 2, s);
// , 4
n = s.rfind("is", 4);
print(n, 2, s);
//
n = s.rfind('s');
print(n, 1, s);
//
n = s.rfind('q');
print(n, 1, s);
// ( s.starts_with("This"))
n = s.rfind("This", 0);
print(n, 4, s);
}
:
: "is" 5
: "is" 2
: "s" 10
: "This" 0
C++:
| LWG 847 | C++98 | ||
| LWG 2064 | C++11 | (3,4) noexcept | |
| LWG 2946 | C++17 | (5) |
, |
| WG | C++11 C++17 |
noexcept (4,5) LWG2064/LWG2946 |
| (public -) | |
| (public -) | |
| (public -) | |
| (public -) | |
| (public -) | |
(C++17) |
(public - std::basic_string_view<CharT,Traits>)
|