std::string::find(...) 사용시 실수..

bool DoTest() {
    std::string temp("TEST0006.ts");

    if (temp.find("TEST") == 0 && temp.find(".m3u8") > 0) {
        return true;
    }

    return false;
}

위 함수를 수행하면 결과는?

결과는 false를 예상했지만... true 가 나온다.
왜? temp.find(".m3u8") 이 -1 이 나오니까 false가 나올꺼 같은데...
c++ standard를 찾아보니...

    size_type find(const _CharT* __s, size_type __pos = 0) const { ...}

으로 되어 있다.
size_type을 찾아보니.. unsigned integral type 이다.

unsigned int에서 -1은 최대값 65535이므로 true가 맞다.

앞으론 실수하지 않아야겠다.. -_-;;

댓글

이 블로그의 인기 게시물

Raspberry pi 한글 설정 및 chromium 설치

Google Test를 이용한 Class의 Private/Protected Member Test