strchr()는 C 스타일 함수이기 때문에 string의 경우 c_str() 함수로 sz(String terminated w/ Zero) 형식으로 변환해주어야 한다.
#include <iostream>
#include <cstring>
using namespace std;
void main()
{
string s = "Hello World !!";
// "Hello World !!" 문자열에서 문자 'o'를 검색한다.
if (strchr(s.c_str(), 'o') != nullptr)
cout << "Found !!" << endl;
else
cout << "Not found !!" << endl;
}
출력
Found !!
'자료구조 & 알고리즘 > 기타' 카테고리의 다른 글
std::replace (0) | 2023.03.14 |
---|---|
unique()를 활용한 연속된 값의 제거 (0) | 2023.03.04 |
공백 관련 처리 (0) | 2023.03.02 |
istream의 기능들 (0) | 2023.03.02 |
정답률보다 오답률이 높을 때 (0) | 2023.02.26 |