std::basic_string<CharT,Traits,Allocator>:: find_last_not_of
|
size_type find_last_not_of
(
const
basic_string
&
str,
size_type pos = npos ) const ; |
(1) |
(C++11부터 noexcept)
(C++20부터 constexpr) |
|
size_type find_last_not_of
(
const
CharT
*
s,
size_type pos, size_type count ) const ; |
(2) | (C++20부터 constexpr) |
|
size_type find_last_not_of
(
const
CharT
*
s, size_type pos
=
npos
)
const
;
|
(3) | (C++20부터 constexpr) |
|
size_type find_last_not_of
(
CharT ch, size_type pos
=
npos
)
const
;
|
(4) |
(C++11부터 noexcept)
(C++20부터 constexpr) |
|
template
<
class
StringViewLike
>
size_type
|
(5) |
(C++17부터)
(C++20부터 constexpr) |
주어진 문자 시퀀스에 포함되지 않은 마지막 문자를 찾습니다. 검색은
[
0
,
pos
]
범위에서만 수행됩니다. 만약 범위 내의 모든 문자가 주어진 문자 시퀀스에서 발견될 경우,
npos
가 반환됩니다.
[
s
,
s
+
count
)
내의 문자들 중 어느 것과도 일치하지 않는 마지막 문자를 찾습니다. 이 범위는 null 문자를 포함할 수 있습니다.
[
s
,
s
+
count
)
가 유효한 범위가 아니라면, 동작은 정의되지 않습니다.
[
s
,
s
+
Traits
::
length
(
s
)
)
가 유효한 범위가 아니라면, 동작은 정의되지 않습니다.
std:: basic_string_view < CharT, Traits >> 가 true 이고 std:: is_convertible_v < const StringViewLike & , const CharT * > 가 false 인 경우입니다.
모든 경우에, 동등성은 Traits::eq 을 호출하여 확인됩니다.
목차 |
매개변수
| str | - | 검색할 문자들을 식별하는 문자열 |
| pos | - | 검색을 종료할 위치 |
| count | - | 검색할 문자들을 식별하는 문자열의 길이 |
| s | - | 검색할 문자들을 식별하는 문자열에 대한 포인터 |
| ch | - | 검색할 문자들을 식별하는 문자 |
| t | - | 검색할 문자들을 식별하는 객체 ( std::basic_string_view 로 변환 가능) |
반환값
발견된 문자의 위치 또는 npos 해당 문자가 발견되지 않을 경우.
예외
const T & , std:: basic_string_view < CharT, Traits >> )
어떤 이유로든 예외가 발생하면, 이 함수는 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).
예제
#include <iostream> #include <string> void show_pos(const std::string& str, std::string::size_type found) { if (found != std::string::npos) std::cout << '[' << found << "] = \'" << str[found] << "\'\n"; else std::cout << "not found\n"; } int main() { std::string str{"abc_123"}; char const* skip_set{"0123456789"}; std::string::size_type str_last_pos{std::string::npos}; show_pos(str, str.find_last_not_of(skip_set)); // [3] = '_' str_last_pos = 2; show_pos(str, str.find_last_not_of(skip_set, str_last_pos)); // [2] = 'c' str_last_pos = 2; show_pos(str, str.find_last_not_of('c', str_last_pos)); // [1] = 'b' const char arr[]{'3', '4', '5'}; show_pos(str, str.find_last_not_of(arr)); // [5] = '2' str_last_pos = 2; std::string::size_type skip_set_size{4}; show_pos(str, str.find_last_not_of(skip_set, str_last_pos, skip_set_size)); // [2] = 'c' show_pos(str, str.find_last_not_of("abc")); // [6] = '3' str_last_pos = 2; show_pos(str, str.find_last_not_of("abc", str_last_pos)); // not found }
출력:
[3] = '_' [2] = 'c' [1] = 'b' [5] = '2' [2] = 'c' [6] = '3' not found
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 141 | C++98 | 오버로드 (1)은 npos 를 반환할 수 있는 경우가 pos >= size ( ) 인 경우로 제한됨 |
이 경우 검색 범위는
[
0
,
size
(
)
)
임
|
| LWG 847 | C++98 | 예외 안전성 보장이 없었음 | 강력한 예외 안전성 보장이 추가됨 |
| LWG 2064 | C++11 | 오버로드 (3,4) 가 noexcept였음 | 제거됨 |
| LWG 2946 | C++17 | 오버로드 (5) 가 일부 경우에 모호성을 야기함 | 템플릿으로 만들어 회피함 |
| P1148R0 |
C++11
C++17 |
오버로드
(4,5)
의 noexcept가
LWG2064/LWG2946에 의해 실수로 제거됨 |
복원됨 |
참고 항목
|
주어진 부분 문자열의 첫 번째 발생을 찾음
(public member function) |
|
|
부분 문자열의 마지막 발생을 찾음
(public member function) |
|
|
문자의 첫 번째 발생을 찾음
(public member function) |
|
|
문자의 첫 번째 부재를 찾음
(public member function) |
|
|
문자의 마지막 발생을 찾음
(public member function) |
|
|
문자의 마지막 부재를 찾음
(public member function of
std::basic_string_view<CharT,Traits>
)
|