◆ std::find()
find(str.begin(), str.end(), i)
- #include <algorithm> 필요
- str인 str.begin()부터 str.end()까지의 범위에서 i가 str 벡터 내에 있다면 i가 있는 인덱스 반환, 그렇지 않으면 indices.end()를 반환
- std::string뿐만 아니라 std::vector, 배열 등에서도 사용 가능
◆ std::string::find()
str.find(문자 또는 스트링 문자열);
- std::string 객체에서만 사용됨
- 주어진 문자열이나 문자가 처음 등장하는 위치를 반환
- 찾지 못한 경우 std::string::npos(-1과 같음)를 반환
if (str.find("abc") != string::npos) return 1; // string::도 무조건 써야 함
else return 0;
728x90