문제

First off, I am a c++ newbie. Excuse me if this question sounds stupid.

I am having a problem with the conversion from unsigned_int to size_t as shown in the VS compiler. Following are the lines of code that causes the compiler to complain.

size_t findNextAlphaNumericPosition(string &str)
{
    for (size_t i = 0; i < str.length; i++)
    {
        if (isalpha(str[i])) return i;
    }

    return -1;
}

It complains when it runs to this line:

for (size_t i = 0; i < str.length; i++)

Any thoughts would be highly appreciated. It stops VS from compiling.

도움이 되었습니까?

해결책

The length member of std::string is a function, so you must call it:

for (size_t i = 0; i < str.length(); i++)
//            Note function call ^^
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top