Вопрос

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