std::basic_string_view<CharT,Traits>:: find
From cppreference.net
<
cpp
|
string
|
basic string view
|
constexpr
size_type find
(
basic_string_view v, size_type pos
=
0
)
const
noexcept
;
|
(1) | (C++17부터) |
|
constexpr
size_type find
(
CharT ch, size_type pos
=
0
)
const
noexcept
;
|
(2) | (C++17부터) |
|
constexpr
size_type find
(
const
CharT
*
s, size_type pos, size_type count
)
const
;
|
(3) | (C++17부터) |
|
constexpr
size_type find
(
const
CharT
*
s, size_type pos
=
0
)
const
;
|
(4) | (C++17부터) |
주어진 문자 시퀀스와 동일한 첫 번째 부분 문자열을 찾습니다.
1)
이 뷰에서 위치
pos
에서 시작하여
v
의 첫 번째 발생을 찾습니다.
2)
다음에 해당함
find
(
basic_string_view
(
std::
addressof
(
ch
)
,
1
)
, pos
)
.
3)
다음에 해당함
find
(
basic_string_view
(
s, count
)
, pos
)
.
4)
다음에 해당함
find
(
basic_string_view
(
s
)
, pos
)
.
목차 |
매개변수
| v | - | 검색할 뷰 |
| pos | - | 검색을 시작할 위치 |
| count | - | 검색할 부분 문자열의 길이 |
| s | - | 검색할 문자 문자열에 대한 포인터 |
| ch | - | 검색할 문자 |
반환값
찾은 부분 문자열의 첫 번째 문자 위치, 또는 npos 해당 부분 문자열이 발견되지 않은 경우.
복잡도
최악의 경우 O( size() * v. size() )입니다.
예제
이 코드 실행
#include <string_view> int main() { using namespace std::literals; constexpr auto str{" long long int;"sv}; static_assert( 1 == str.find("long"sv) && "<- find(v , pos = 0)" && 6 == str.find("long"sv, 2) && "<- find(v , pos = 2)" && 0 == str.find(' ') && "<- find(ch, pos = 0)" && 2 == str.find('o', 1) && "<- find(ch, pos = 1)" && 2 == str.find("on") && "<- find(s , pos = 0)" && 6 == str.find("long double", 5, 4) && "<- find(s , pos = 5, count = 4)" ); static_assert(str.npos == str.find("float")); }
참고 항목
|
부분 문자열의 마지막 발생 위치 찾기
(public member function) |
|
|
문자들의 첫 번째 발생 위치 찾기
(public member function) |
|
|
문자들의 마지막 발생 위치 찾기
(public member function) |
|
|
문자들이 없는 첫 번째 위치 찾기
(public member function) |
|
|
문자들이 없는 마지막 위치 찾기
(public member function) |
|
|
주어진 부분 문자열의 첫 번째 발생 위치 찾기
(
std::basic_string<CharT,Traits,Allocator>
의
public member function)
|