std:: strstr
From cppreference.net
|
헤더 파일에 정의됨
<cstring>
|
||
|
const
char
*
strstr
(
const
char
*
haystack,
const
char
*
needle
)
;
|
||
|
char
*
strstr
(
char
*
haystack,
const
char
*
needle
)
;
|
||
바이트 문자열 needle 이 가리키는 바이트 문자열에서 첫 번째 발생 위치를 찾습니다. haystack 종료 널 문자는 비교되지 않습니다.
목차 |
매개변수
| haystack | - | 검사할 null로 종료되는 바이트 문자열에 대한 포인터 |
| needle | - | 검색할 null로 종료되는 바이트 문자열에 대한 포인터 |
반환값
발견된 부분 문자열의 첫 번째 문자를 가리키는 포인터, 또는 해당 문자가 발견되지 않으면 널 포인터를 반환합니다. 만약 needle 이 빈 문자열을 가리키면, haystack 이 반환됩니다.
예제
이 코드 실행하기
#include <cstring> #include <iomanip> #include <iostream> int main() { const char* str = "Try not. Do, or do not. There is no try."; const char* target = "not"; for (const char* result = str; (result = std::strstr(result, target)); ++result) std::cout << "Found " << std::quoted(target) << " starting at (" << result - str << "): " << std::quoted(result) << '\n'; }
출력:
Found "not" starting at (4): "not. Do, or do not. There is no try." Found "not" starting at (19): "not. There is no try."
참고 항목
|
주어진 부분 문자열의 첫 번째 발생 위치를 찾음
(
std::basic_string<CharT,Traits,Allocator>
의
public member function)
|
|
|
와이드 문자열 내에서 다른 와이드 문자열의 첫 번째 발생 위치를 찾음
(function) |
|
|
문자의 첫 번째 발생 위치를 찾음
(function) |
|
|
문자의 마지막 발생 위치를 찾음
(function) |
|
|
C documentation
for
strstr
|
|