Question

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.

Was it helpful?

Solution

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 ^^
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top