Error: E0254 type name is not allowed

0

I'm getting this error in this code:

bool Configuration::GetConfigBlockLine(ifstream& file, string& key, string& value)
{
    string line;

    // end of file
    while( !file.eof() )
    {
        // read line from config file
        getline( file, line );
        TrimString( line );

        // end of object's data 
        if( line.compare( "#end" ) == 0 )
            return false;

        size_t p = line.find( '=' );
        if( p != string.npos )
        {
            // key
            key = line.substr( 0, p );
            TrimString( key );

            // value
            value = line.substr( p + 1, line.length() );
            TrimString( value );

            // key - value pair read successfully
            return true;
        }
    }

    // error
    return false;
}

Apparently it says that string is not an allowed name, in if( p != string.npos ) but why does this error occur and how can I fix it.

    
asked by anonymous 07.11.2018 / 03:38

1 answer

3

The correct one is "string :: npos" and not "string.npos".

In the code snippet

size_t p = line.find('='); // linha 1
if (p != string::npos)     // linha 2

line 1 looks for the position (index) of the character '=' inside the string "line"

In line 2, the comparison "p! = string :: npos" is true in the case of EXIST the '=' character inside the string "line".

    
07.11.2018 / 03:45