반응형
c++의 std::string에는 contains함수가 존재하지 않는다. 이를 대신하기 위해 find 함수가 존재한다.
728x90
[function origin]
size_t find (const string& str, size_t pos = 0) const;
size_t find (const char* s, size_t pos = 0) const;
size_t find (const char* s, size_t pos, size_t n) const;
size_t find (char c, size_t pos = 0) const;
[parameter]
str : 찾고자 하는 문자열
pos : str을 pos위치부터 찾기 시작
s : 캐릭터형의 배열을 가리키는 포인터
n : 연속으로 일치해야 하는 최소 길이
c : 찾고자 하는 캐릭터
[return]
첫 번째로 일치하는 문자의 위치 return
일치하는 위치를 찾지 못한 경우 string::npos return
[sample]
std::string str = "example string";
std::string str2 = "str";
if (str.find(str2) != string::npos) {
//.. found
}
else
{
//.. not found
}
SMALL
반응형
'개발 > C++' 카테고리의 다른 글
C++20 신규 기능 정리 (0) | 2023.01.25 |
---|---|
Boost Geometry 자주 사용하는 함수 정리 1편 (0) | 2022.11.02 |
std::unordered_map 정렬하기 (0) | 2022.10.06 |
[Boost Geometry] points -> polygon cluster (0) | 2022.08.10 |
std::string tokenizing 방법 (0) | 2022.04.19 |