std:: strchr
From cppreference.net
|
헤더 파일에 정의됨
<cstring>
|
||
|
const
char
*
strchr
(
const
char
*
str,
int
ch
)
;
|
||
|
char
*
strchr
(
char
*
str,
int
ch
)
;
|
||
static_cast < char > ( ch ) 문자를 str 가 가리키는 바이트 문자열에서 처음으로 발견되는 위치를 찾습니다.
종료 널 문자는 문자열의 일부로 간주되며 ' \0 ' 를 검색하면 찾을 수 있습니다.
목차 |
매개변수
| str | - | 분석할 null로 종료되는 바이트 문자열에 대한 포인터 |
| ch | - | 검색할 문자 |
반환값
str 에서 발견된 문자에 대한 포인터, 해당 문자가 발견되지 않으면 null 포인터를 반환합니다.
예제
이 코드 실행
#include <cstring> #include <iostream> int main() { const char* str = "Try not. Do, or do not. There is no try."; char target = 'T'; const char* result = str; while ((result = std::strchr(result, target)) != nullptr) { std::cout << "Found '" << target << "' starting at '" << result << "'\n"; // Increment result, otherwise we'll find target at the same location ++result; } }
출력:
Found 'T' starting at 'Try not. Do, or do not. There is no try.' Found 'T' starting at 'There is no try.'
참고 항목
|
배열에서 문자의 첫 번째 발생을 검색합니다
(함수) |
|
|
주어진 부분 문자열의 첫 번째 발생을 찾습니다
(
std::basic_string<CharT,Traits,Allocator>
의
public member function)
|
|
|
와이드 문자열에서 와이드 문자의 첫 번째 발생을 찾습니다
(함수) |
|
|
문자의 마지막 발생을 찾습니다
(함수) |
|
|
구분자 집합에서 임의의 문자의 첫 번째 위치를 찾습니다
(함수) |
|
|
C documentation
for
strchr
|
|