728x90
반응형
string contains
c++ 에는 아쉽게도 String 의 contains 기능이 없다.
간단하게 한줄로 구현이 가능하다.
1. cplusplus 에서 사용한 방법
std::string str ("Who Am I");
std::string str2 ("Am");
// different member versions of find in the same order as above:
std::size_t found = str.find(str2);
if (found!=std::string::npos)
std::cout << "find Am " << found << '\n';
2. 좀더 간결한 방법 난 이방법을 제일 많이 쓴다.
std::string str ("Who Am I");
std::string str2 ("Am");
// different member versions of find in the same order as above:
if (str.find(str2)!=std::string::npos)
std::cout << "find Am " << '\n';
반응형
3. strstr을 사용하는 방법
std::string str ("Who Am I");
std::string str2 ("Am");
if (std::strstr(str.c_str(), str2.c_str()))
std::cout << "find Am " << found << '\n';
728x90
반응형
'Language > C++' 카테고리의 다른 글
[C++] Crypto++ 을 이용한 string 암호화 구현 (0) | 2021.07.16 |
---|---|
[C++] lambda(람다) (0) | 2021.04.06 |
댓글